fixed BUG-78 (deleted recursively too far - took out parent_dir), also deleting from the viewer page works with Delete key too. Removed debugs in viewer for fullscreen

This commit is contained in:
2022-01-14 13:49:39 +11:00
parent 3678a5892f
commit bd7cae6037
4 changed files with 22 additions and 40 deletions

View File

@@ -595,7 +595,6 @@ def CleanFileFromBin(job, e):
# use ctime as that will be when the file was moved into the Bin path
if (now - stat.st_ctime)/SECS_IN_A_DAY >= settings.bin_cleanup_file_age:
try:
print( f"would physically remove this file: {fname}, e={e}")
os.remove( fname )
except Exception as ex:
AddLogForJob(job, f"ERROR: Tried to delete old file: {ex}" )
@@ -675,7 +674,7 @@ def RunJob(job):
elif job.name == "clean_bin":
JobCleanBin(job)
else:
print("ERROR: Requested to process unknown job type: {}".format(job.name))
FinishJob(job, f"ERROR: Requested to process unknown job type: {job.name}", "Failed")
# okay, we finished a job, so check for any jobs that are dependant on this and run them...
# session.close()
if job.pa_job_state != "Completed":
@@ -733,9 +732,10 @@ def HandleJobs(first_run=False):
if job.wait_for != None:
j2 = session.query(Job).get(job.wait_for)
if not j2:
print ("ERROR: job.wait_for ({}) does not exist in below? ".format( job.wait_for ))
AddLogForJob( job, f"ERROR: waiting for a job#({job.wait_for}) that does not exist? ")
print(f"ERROR: job.wait_for ({job.wait_for}) does not exist in below? " )
for j in session.query(Job).all():
print ("ERROR: j={}".format(j.id))
print(f"ERROR: j={j.id}")
continue
if j2.pa_job_state != 'Completed':
continue
@@ -913,7 +913,7 @@ def RemoveEmtpyDirFromFS( job, del_me ):
try:
os.rmdir( del_me.FullPathOnFS() )
except Exception as e:
print( f"ERROR: Failed to remove dir from filesystem - which={del_me.FullPathOnFS()}, err: {e}")
AddLogForJob( job, f"ERROR: Failed to remove dir from filesystem - which={del_me.FullPathOnFS()}, err: {e}")
return
def RemoveEmptyDirFromDB( job, del_me ):
@@ -935,12 +935,14 @@ def CleanUpDirInDB(job, e):
content = session.query(Entry).join(EntryDirLink).filter(EntryDirLink.dir_eid==e.id).first()
if not content:
print( f" Dir {e.FullPathOnFS()} - {e.id} is empty - removing it" )
print( f" Entry {e}" )
# if no in_dir, we are at the root of the path, STOP
if not e.in_dir:
print( " Parent is empty, so NEVER delete this entry, returning" )
return
# okay remove this empty dir
RemoveEmtpyDirFromFS( job, e )
RemoveEmptyDirFromDB( job, e )
# if no in_dir, we are at the root of the path, STOP
if not e.in_dir:
return
# get an Entry from DB (in_dir is a Dir/we need the ORM entry for code to work)
parent_dir = session.query(Entry).get(e.in_dir.eid)
print( f" Dir {e.FullPathOnFS()} is in {parent_dir.FullPathOnFS()} ({parent_dir.id}) -> check next" )
@@ -984,7 +986,7 @@ def RestoreFile(job,restore_me):
dst=dst_dir + '/' + restore_me.name
os.replace( src, dst )
except Exception as e:
print( f"ERROR: Failed to restores (mv) file on filesystem - which={src} to {dst}, err: {e}")
AddLogForJob( job, f"ERROR: Failed to restores (mv) file on filesystem - which={src} to {dst}, err: {e}")
# need these for AddDir calls below to work
orig_file_details = session.query(DelFile).get(restore_me.id)
@@ -1036,7 +1038,7 @@ def MoveFileToRecycleBin(job,del_me):
if DEBUG:
print( f"MoveFileToRecycleBin({job.id},{del_me.name}): os.replace {src} with {dst} " )
except Exception as e:
print( f"ERROR: Failed to remove file from filesystem - which={src}, err: {e}")
AddLogForJob( job, f"ERROR: Failed to remove file from filesystem - which={src}, err: {e}")
# need these for AddDir calls below to work
bin_path=session.query(Path).join(PathType).filter(PathType.name=='Bin').first()