Merge pull request #2230 from jberry-suse/osclib-util-rmtree-nfs-safe

osclib/cache: utilize rmtree_nfs_safe().
This commit is contained in:
Jimmy Berry 2019-09-23 18:45:31 -05:00 committed by GitHub
commit 83f1d51c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import hashlib
import os
import osc.core
import re
import shutil
import sys
try:
@ -25,6 +24,7 @@ from io import BytesIO
from osc import conf
from osc.core import urlopen
from osclib.cache_manager import CacheManager
from osclib.util import rmtree_nfs_safe
from time import time
try:
@ -246,12 +246,12 @@ class Cache(object):
if os.path.exists(path):
if conf.config['debug']: print('CACHE_DELETE_PROJECT', apiurl, project, file=sys.stderr)
shutil.rmtree(path)
rmtree_nfs_safe(path)
@staticmethod
def delete_all():
if os.path.exists(Cache.CACHE_DIR):
shutil.rmtree(Cache.CACHE_DIR)
rmtree_nfs_safe(Cache.CACHE_DIR)
@staticmethod
def match(url):

View File

@ -177,3 +177,17 @@ def sha1_short(data):
data = data.encode('utf-8')
return hashlib.sha1(data).hexdigest()[:7]
def rmtree_nfs_safe(path, attempts=5):
import shutil
try:
shutil.rmtree(path)
except OSError as e:
# Directory not empty due to slow filesystem (see #1326 old occurance).
if attempts <= 0 or e.errno != 39:
raise e
from time import sleep
sleep(0.25)
rmtree_nfs_safe(path, attempts - 1)