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:
6
TODO
6
TODO
@@ -1,16 +1,18 @@
|
||||
## GENERAL
|
||||
* on start up, should validate the import/storage/recycle bin paths exist and spit an error if they dont
|
||||
* dont process duplicates from Bin
|
||||
|
||||
* issue where someone could call IP .../Imp/photos and SP .../Sto/photos and then static/photos is ambiguous:
|
||||
-- DONE: make path prefix by static/<ptype.name>/ so that files are in: static/<ptype.name>/in_path.pp/dir.rel_path/
|
||||
-- then deleting below would just path_prefix from static/storage to .pa_bin/storage, etc.
|
||||
-- need to create the subdir if it does not exist in recycle_bin_path
|
||||
*** THINK: should bin be a normal path/dir name, and in static too -- I think it will be easier in hindsight -- so need to change dst_dir when os.replace is used
|
||||
-- need to be able to view recycle bin (should be simple when we have path_types) &&& should able to consolidate the files_ip/files_sp/files_rb? route handling functions
|
||||
-- could also allow undelete per file / show content as another Files->View and more like storage (i.e. show folders)
|
||||
* storage_path viewing needs to be by folder / not a big grab bag of files (by default - DONE)
|
||||
-- BUG: issue with view by Day, etc. we print out day even if the Entry is not in the cwd
|
||||
-- TODO: Need to toggle the view if I want, and when viewing storage area, change single-click to be view file again, and right-click to be my context menu
|
||||
* import_path can be folder view and works (need toggle as above)
|
||||
* * import_path can be folder view and is DONE but needs toggle as above
|
||||
* need a way for search results to show we found something in import_path or storage_path:
|
||||
- now we can use the in_path, then have a series of icons, e.g. disk for storage, ? for import, and bin for recycling (before the blue path)--maybe even show different colours, e.g. info for import, primary for storage and danger for bin?
|
||||
* handle thumbs:
|
||||
@@ -18,6 +20,8 @@
|
||||
and potentially other stuff like .pa_bin if its in storage/import folder?
|
||||
* AddJobForLog can absorb DEBUGs, etc. in fact fix up logging in general
|
||||
* comment your code
|
||||
* more OO goodness :)
|
||||
|
||||
|
||||
## DB
|
||||
Need to think about...
|
||||
|
||||
@@ -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('-')
|
||||
|
||||
Reference in New Issue
Block a user