real fix for BUG-64, can now move a directory between import/storage too... Still have move button disabled on selecting a folder in GUI - to be fixed, then we can move 111 Working dir back to the import dir
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
# global debug setting
|
||||
DEBUG=False
|
||||
DEBUG=True
|
||||
|
||||
### SQLALCHEMY IMPORTS ###
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
@@ -969,6 +969,8 @@ def MoveFileToRecycleBin(job,del_me):
|
||||
src=del_me.FullPathOnFS()
|
||||
dst=dst_dir + '/' + del_me.name
|
||||
os.replace( src, dst )
|
||||
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}")
|
||||
|
||||
@@ -1005,8 +1007,8 @@ def MoveFileToRecycleBin(job,del_me):
|
||||
return
|
||||
|
||||
####################################################################################################################################
|
||||
# Function that moves a file into a new folder in the storage path - if needed it makes the folder on the FS,
|
||||
# moves the file into the folder on the FS and then changes the database path to the relevant Storage path
|
||||
# Function that moves a file into a new folder in any path (usually form import to storage) - if needed it makes the folder on the FS,
|
||||
# moves the file into the folder on the FS and then changes the path to the appropriate one
|
||||
####################################################################################################################################
|
||||
def MoveFileToNewFolderInStorage(job,move_me, dst_storage_path, dst_rel_path):
|
||||
if DEBUG:
|
||||
@@ -1028,8 +1030,8 @@ def MoveFileToNewFolderInStorage(job,move_me, dst_storage_path, dst_rel_path):
|
||||
parent_dir=session.query(Dir).join(PathDirLink).filter(PathDirLink.path_id==dst_storage_path.id).first()
|
||||
|
||||
# okay, go through new relative path and AddDir any missing subdirs of this
|
||||
# path (think Import/Dir1/Dir2) which b/c we have bin_path in AddDir will
|
||||
# create Bin/Import, Bin/Import/Dir1, Bin/Import/Dir1/Dir2
|
||||
# path (think Import/Dir1/Dir2) which b/c we have dst_storage_path in AddDir will
|
||||
# create Storage/Dir1, Storage/Dir1/Dir2
|
||||
part_rel_path=""
|
||||
for dirname in dst_rel_path.split("/"):
|
||||
part_rel_path += f"{dirname}"
|
||||
@@ -1042,11 +1044,33 @@ def MoveFileToNewFolderInStorage(job,move_me, dst_storage_path, dst_rel_path):
|
||||
print( f"now should change {move_me} in_dir to {new_dir} created above in {dst_storage_path}" )
|
||||
move_me.in_dir = new_dir
|
||||
move_me.in_path = dst_storage_path
|
||||
if move_me.type.name == "Directory":
|
||||
if DEBUG:
|
||||
print( f"{move_me.name} is a dir, so reset its dir_details path to the new path too" )
|
||||
move_me.dir_details.in_path = dst_storage_path
|
||||
move_me.dir_details.rel_path = dst_rel_path + '/' + move_me.dir_details.rel_path
|
||||
ResetAnySubdirPaths( move_me, dst_storage_path, dst_rel_path )
|
||||
if DEBUG:
|
||||
print( f"DONE change of {move_me} in_dir to {new_dir} created above" )
|
||||
session.add(move_me)
|
||||
AddLogForJob(job, f"{move_me.name} - (moved to {os.path.dirname(move_me.FullPathOnFS())})" )
|
||||
return
|
||||
|
||||
def ResetAnySubdirPaths( moving_dir, dst_storage_path, dst_rel_path ):
|
||||
if DEBUG:
|
||||
print( f"ResetAnySubdirPaths( {moving_dir.name}, {dst_storage_path.path_prefix}, {dst_rel_path} )" )
|
||||
sub_dirs = session.query(Entry).join(FileType).join(EntryDirLink).filter(EntryDirLink.dir_eid==moving_dir.id).filter(FileType.name=='Directory').all()
|
||||
for sub in sub_dirs:
|
||||
if DEBUG:
|
||||
print( f"ResetAnySubdirPaths: WAS sub={sub.name}, ip={sub.in_dir.in_path.path_prefix}, rp={sub.dir_details.rel_path}" )
|
||||
sub.in_path = dst_storage_path
|
||||
sub.dir_details.in_path = dst_storage_path
|
||||
sub.dir_details.rel_path = dst_rel_path + '/' + sub.dir_details.rel_path
|
||||
if DEBUG:
|
||||
print( f"ResetAnySubdirPaths: NOW sub={sub.name}, ip={sub.in_dir.in_path.path_prefix}, rp={sub.dir_details.rel_path}" )
|
||||
ResetAnySubdirPaths( sub, dst_storage_path, dst_rel_path )
|
||||
return
|
||||
|
||||
####################################################################################################################################
|
||||
# Convenience function to remove a dir from the database - and its associated links
|
||||
####################################################################################################################################
|
||||
@@ -1585,7 +1609,8 @@ def JobMoveFiles(job):
|
||||
|
||||
for jex in job.extra:
|
||||
if 'eid-' in jex.name:
|
||||
move_me=session.query(Entry).join(File).filter(Entry.id==jex.value).first()
|
||||
# move_me=session.query(Entry).join(File).filter(Entry.id==jex.value).first()
|
||||
move_me=session.query(Entry).get(jex.value)
|
||||
MoveFileToNewFolderInStorage(job, move_me, dst_storage_path, f"{prefix}{suffix}" )
|
||||
now=datetime.now(pytz.utc)
|
||||
next_job=Job(start_time=now, last_update=now, name="checkdups", state="New", wait_for=None, pa_job_state="New", current_file_num=0 )
|
||||
|
||||
Reference in New Issue
Block a user