first-pass of deleting a file moving to the bin instead, not in right spot on FS/ path&rel_path, and no visualisation yet

This commit is contained in:
2021-05-24 07:42:08 +10:00
parent 74943f6112
commit 8dc98dd368
2 changed files with 45 additions and 25 deletions

View File

@@ -545,20 +545,48 @@ def ResetExistsOnFS(job, path):
# used when scanning and a file has been removed out from under PA, or
# when we remove duplicates
def RemoveFileFromDB(id):
print( "DDP: this should just switch the path link to the recycle bin and maybe udpate rel_path?")
# okay, so 'id' will have EntryDirLink -> PathDirLink needs a change, what about rel_path?
pdl = session.query(PathDirLink).join(Dir).join(EntryDirLink).filter(EntryDirLink.entry_id==id).first()
print( pdl )
# think this needs to just switch pdl.path_id to bin???
session.query(EntryDirLink).filter(EntryDirLink.entry_id==id).delete()
session.query(File).filter(File.eid==id).delete()
session.query(Entry).filter(Entry.id==id).delete()
return
# Actually moves the physical file from its current real directory to a subdir of the recycle bin path
def RemoveFileFromFS( del_me ):
try:
settings = session.query(Settings).first()
dst_dir=settings.recycle_bin_path + '/' + del_me.in_dir.in_path.path_prefix.replace('static/','') + '/' + del_me.in_dir.rel_path + '/'
os.makedirs( dst_dir,mode=0o777, exist_ok=True )
src=del_me.FullPathOnFS()
dst=dst_dir + '/' + del_me.name
os.replace( src, dst )
except Exception as e:
print( f"Failed to remove file from filesystem - which={src}, err: {e}")
return
def MoveFileToRecycleBin(job,del_me):
try:
settings = session.query(Settings).first()
dst_dir=settings.recycle_bin_path + '/' + del_me.in_dir.in_path.path_prefix.replace('static/','') + '/' + del_me.in_dir.rel_path + '/'
os.makedirs( dst_dir,mode=0o777, exist_ok=True )
src=del_me.FullPathOnFS()
dst=dst_dir + '/' + del_me.name
os.replace( src, dst )
except Exception as e:
print( f"Failed to remove file from filesystem - which={src}, err: {e}")
bin=session.query(Path).join(PathType).filter(PathType.name=='Bin').first()
print("bin={bin}")
print("del_me={del_me}")
new_rel_path=del_me.in_dir.in_path.path_prefix.replace('static/','')
# if there is a relative path on this dir, add it to the new_rel_path as there is only ever 1 Bin path
if len(del_me.in_dir.rel_path):
new_rel_path += '/' + del_me.in_dir.rel_path
print("new_rel_path={new_rel_path}")
new_dir = AddDir(job, new_rel_path, None, new_rel_path, bin )
print( "new_dir={new_dir}" )
del_me.in_dir = new_dir
return
# Convenience function to remove a dir from the database - and its associated links
def RemoveDirFromDB(id):
session.query(EntryDirLink).filter(EntryDirLink.entry_id==id).delete()
@@ -954,19 +982,6 @@ def CheckForDups(job):
FinishJob(job, f"Finished looking for duplicates")
return
# Actually moves the physical file from its current real directory to a subdir of the recycle bin path
def RemoveFileFromFS( del_me ):
try:
settings = session.query(Settings).first()
dst_dir=settings.recycle_bin_path + '/' + del_me.in_dir.in_path.path_prefix.replace('static/','') + '/' + del_me.in_dir.rel_path + '/'
os.makedirs( dst_dir,mode=0o777, exist_ok=True )
src=del_me.FullPathOnFS()
dst=dst_dir + '/' + del_me.name
os.replace( src, dst )
except Exception as e:
print( f"Failed to remove file from filesystem - which={src}, err: {e}")
return
def RemoveDups(job):
AddLogForJob(job, f"INFO: Starting Remove Duplicates job...")
# as checkdups covers all dups, delete all future dups messages, and Withdraw future checkdups jobs
@@ -1001,8 +1016,9 @@ def RemoveDups(job):
AddLogForJob(job, f"Keep duplicate file: {found.FullPathOnFS()}" )
for del_me in del_me_lst:
AddLogForJob(job, f"Remove duplicate (per file dup) file: {del_me.FullPathOnFS()}" )
RemoveFileFromFS( del_me )
RemoveFileFromDB(del_me.id)
MoveFileToRecycleBin(job,del_me)
# RemoveFileFromFS( del_me )
# RemoveFileFromDB(del_me.id)
if 'kdid-' in jex.name:
_, which = jex.name.split('-')