From 9f2165c04dec887e46d3c47cd4339e9b6a893347 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 2 Oct 2021 14:48:50 +1000 Subject: [PATCH] reset sub dir path properly based on parents path. Also fixed bug-69 - FullPathOnFS() was wrong for first dir in a path --- pa_job_manager.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pa_job_manager.py b/pa_job_manager.py index 8b1b0f9..d27e7f1 100644 --- a/pa_job_manager.py +++ b/pa_job_manager.py @@ -160,15 +160,17 @@ class Entry(Base): file_details = relationship( "File", uselist=False ) in_dir = relationship ("Dir", secondary="entry_dir_link", uselist=False ) + # DDP: I think I need to test this outside of larger code, I think a + # directory has a full path of real full Path + '/' + self.name def FullPathOnFS(self): if self.in_dir: s=self.in_dir.in_path.path_prefix + '/' if len(self.in_dir.rel_path) > 0: s += self.in_dir.rel_path + '/' + s += self.name # this occurs when we have a dir that is the root of a path else: - s=self.dir_details.in_path.path_prefix+'/' - s += self.name + s=self.dir_details.in_path.path_prefix return s def __repr__(self): @@ -1011,6 +1013,7 @@ def MoveFileToRecycleBin(job,del_me): # 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): + orig_parent_dir_e=session.query(Entry).get(move_me.in_dir.eid) if DEBUG: print( f"MoveFileToNewFolderInStorage: {move_me} to {dst_storage_path} in new? folder: {dst_storage_path}") try: @@ -1048,27 +1051,28 @@ def MoveFileToNewFolderInStorage(job,move_me, dst_storage_path, dst_rel_path): 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 ) + move_me.dir_details.rel_path = move_me.in_dir.rel_path+'/'+move_me.name + ResetAnySubdirPaths( move_me, dst_storage_path, move_me.dir_details.rel_path ) if DEBUG: print( f"DONE change of {move_me} in_dir to {new_dir} created above" ) session.add(move_me) + CleanUpDirInDB(job, orig_parent_dir_e) 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 ): +def ResetAnySubdirPaths( moving_dir, dst_storage_path, parent_rel_path ): if DEBUG: - print( f"ResetAnySubdirPaths( {moving_dir.name}, {dst_storage_path.path_prefix}, {dst_rel_path} )" ) + print( f"ResetAnySubdirPaths( {moving_dir.name}, {dst_storage_path.path_prefix}, {parent_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 + sub.dir_details.rel_path = parent_rel_path + '/' + sub.name 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 ) + ResetAnySubdirPaths( sub, dst_storage_path, sub.dir_details.rel_path ) return ####################################################################################################################################