From 81f8807cdaceb489c2b5cff447c51efbb1b08c02 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Wed, 18 Sep 2019 21:10:49 -0500 Subject: [PATCH 1/2] osclib/util: provide rmtree_nfs_safe(). Still occurs and when in obs_operator context is even more annoying. --- osclib/util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osclib/util.py b/osclib/util.py index 73240d70..e2bfea34 100644 --- a/osclib/util.py +++ b/osclib/util.py @@ -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) From 5c96529c6581b3e6ce008d6720f848b1d5ec0f99 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Wed, 18 Sep 2019 21:37:51 -0500 Subject: [PATCH 2/2] osclib/cache: utilize rmtree_nfs_safe(). --- osclib/cache.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osclib/cache.py b/osclib/cache.py index 5c0bcda4..2f572f7b 100644 --- a/osclib/cache.py +++ b/osclib/cache.py @@ -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):