Skip to content

Commit

Permalink
check that directory exist before deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Dec 4, 2024
1 parent 62ccf1e commit 34d8c9e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions agent/worker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,10 @@ def task_clear_tasks_dir(self):
self.logger.info("Start background task: Clearing Tasks data")
try:
task_dir = constants.AGENT_TASKS_DIR()
shutil.move(task_dir, tmp_dir)
os.makedirs(task_dir)
shutil.rmtree(tmp_dir)
if os.path.exists(task_dir):
shutil.move(task_dir, tmp_dir)
os.makedirs(task_dir)
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear tasks data", exc_info=True)
else:
Expand All @@ -718,9 +719,10 @@ def task_clear_pip_cache(self):
elif constants.SHOULD_CLEAN_PIP_CACHE():
self.logger.info("Start background task: Clearing pip cache")
try:
shutil.move(constants.APPS_PIP_CACHE_DIR(), tmp_dir)
os.makedirs(constants.APPS_PIP_CACHE_DIR())
shutil.rmtree(tmp_dir)
if os.path.exists(constants.APPS_PIP_CACHE_DIR()):
shutil.move(constants.APPS_PIP_CACHE_DIR(), tmp_dir)
os.makedirs(constants.APPS_PIP_CACHE_DIR())
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear pip cache", exc_info=True)
else:
Expand All @@ -745,9 +747,10 @@ def task_clear_apps_data(self):
elif constants.SHOULD_CLEAN_APPS_DATA():
self.logger.info("Start background task: Clearing apps data")
try:
shutil.move(constants.AGENT_APPS_CACHE_DIR(), tmp_dir)
os.makedirs(constants.AGENT_APPS_CACHE_DIR())
shutil.rmtree(tmp_dir)
if os.path.exists(constants.AGENT_APPS_CACHE_DIR()):
shutil.move(constants.AGENT_APPS_CACHE_DIR(), tmp_dir)
os.makedirs(constants.AGENT_APPS_CACHE_DIR())
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear apps data", exc_info=True)
else:
Expand All @@ -770,9 +773,10 @@ def task_clear_apps_data(self):
elif constants.SHOULD_CLEAN_APPS_DATA():
self.logger.info("Start background task: Clearing apps data")
try:
shutil.move(constants.SUPERVISELY_SYNCED_APP_DATA_CONTAINER(), tmp_dir)
os.makedirs(constants.SUPERVISELY_SYNCED_APP_DATA_CONTAINER())
shutil.rmtree(tmp_dir)
if os.path.exists(constants.SUPERVISELY_SYNCED_APP_DATA_CONTAINER()):
shutil.move(constants.SUPERVISELY_SYNCED_APP_DATA_CONTAINER(), tmp_dir)
os.makedirs(constants.SUPERVISELY_SYNCED_APP_DATA_CONTAINER())
shutil.rmtree(tmp_dir)
except:
self.logger.warn("Background task error: Failed to clear apps data", exc_info=True)
else:
Expand Down

0 comments on commit 34d8c9e

Please sign in to comment.