Skip to content

Commit

Permalink
fix: use full paths when deleting old logs thus avoiding os.chdir
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Jul 19, 2023
1 parent 4f32015 commit 8cb436c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/DIRAC/WorkloadManagementSystem/Agent/PilotLoggingAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ def clearOldPilotLogs(self, pilotLogPath):
files = os.listdir(pilotLogPath)
seconds = int(self.clearPilotsDelay) * 86400
currentTime = time.time()
os.chdir(pilotLogPath)

for file in files:
modifTime = os.stat(file).st_mtime
fullpath = os.path.join(pilotLogPath, file)
modifTime = os.stat(fullpath).st_mtime
if modifTime < currentTime - seconds:
self.log.debug(f" Deleting old log : {file}")
self.log.debug(f" Deleting old log : {fullpath}")
try:
os.remove(file)
os.remove(fullpath)
except Exception as excp:
self.log.exception(f"Cannot remove an old log file after {file}", lException=excp)
self.log.exception(f"Cannot remove an old log file after {fullpath}", lException=excp)

0 comments on commit 8cb436c

Please sign in to comment.