From 11a7a0f269d10a859766bde332a4aa33c3547b27 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 13 Feb 2011 20:50:17 -0500 Subject: [PATCH] Cache reattachment for File browser MoveTo operation + code cleanup --- rtgui/filecatalog.cc | 57 ++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 5b829b879..16369f85d 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -576,16 +576,16 @@ void FileCatalog::copyMoveRequested (std::vector tbe, bool m for (unsigned int i=0; ifilename; Glib::ustring src_Dir = Glib::path_get_dirname(src_fPath); - Glib::RefPtr file = Gio::File::create_for_path ( src_fPath ); - if( !file ) continue; // if file is missing - skip it + Glib::RefPtr src_file = Gio::File::create_for_path ( src_fPath ); + if( !src_file ) continue; // if file is missing - skip it - Glib::ustring fname=file->get_basename(); + Glib::ustring fname=src_file->get_basename(); Glib::ustring fname_noExt = removeExtension(fname); Glib::ustring fname_Ext = getExtension(fname); - // construct destinations File Paths - Glib::ustring destfPath = dest_Dir + "/" + fname; - Glib::ustring destfPath_param= destfPath + paramFileExtension; + // construct destination File Paths + Glib::ustring dest_fPath = Glib::build_filename (dest_Dir, fname); + Glib::ustring dest_fPath_param= dest_fPath + paramFileExtension; if (moveRequested && (src_Dir==dest_Dir)) continue; /* comparison of src_Dir and dest_Dir is done per image for compatibility with @@ -593,44 +593,49 @@ void FileCatalog::copyMoveRequested (std::vector tbe, bool m filecopymovecomplete = false; i_copyindex = 1; - while(!filecopymovecomplete){ // should we limit the number of iteration attempts here? (i_copyindex<100)? - if (!safe_file_test(destfPath, Glib::FILE_TEST_EXISTS) && !safe_file_test(destfPath_param, Glib::FILE_TEST_EXISTS)){ + while(!filecopymovecomplete){ + // check for filename conflicts at destination - prevent overwriting (actually RT will crash on overwriting attempt) + if (!safe_file_test(dest_fPath, Glib::FILE_TEST_EXISTS) && !safe_file_test(dest_fPath_param, Glib::FILE_TEST_EXISTS)){ // copy/move file to destination - Glib::RefPtr dest_file = Gio::File::create_for_path ( destfPath ); + Glib::RefPtr dest_file = Gio::File::create_for_path ( dest_fPath ); if (moveRequested) { + // move file + src_file->move(dest_file); + // re-attach cache files + cacheMgr->renameEntry (src_fPath, tbe[i]->thumbnail->getMD5(), dest_fPath); // remove from browser FileBrowserEntry* t = fileBrowser->delEntry (src_fPath); - // remove from cache - // !!! this could be optimized to re-attach cache files and avoid their regeneration - cacheMgr->deleteEntry (src_fPath); - // move file - file->move(dest_file); } else - file->copy(dest_file); + src_file->copy(dest_file); + + + // attempt to copy/move paramFile only if it exist next to the src + Glib::RefPtr scr_param = Gio::File::create_for_path ( src_fPath + paramFileExtension ); - // attempt to copy/move paramFile only if it exist - Glib::RefPtr file_param = Gio::File::create_for_path ( src_fPath + paramFileExtension ); if (safe_file_test( src_fPath + paramFileExtension, Glib::FILE_TEST_EXISTS)){ - Glib::RefPtr dest_param = Gio::File::create_for_path ( destfPath_param); + Glib::RefPtr dest_param = Gio::File::create_for_path ( dest_fPath_param); // copy/move paramFile to destination if (moveRequested){ - /* comparison of src_fPath and destfPath is done per image for a compatibility with - possible future use with collections where each file's source path may be different.*/ - file_param->move(dest_param); + if (safe_file_test( dest_fPath + paramFileExtension, Glib::FILE_TEST_EXISTS)){ + // profile already got copied to destination from cache after cacheMgr->renameEntry + // delete source profile as cleanup + safe_g_remove (src_fPath + paramFileExtension); + } + else + scr_param->move(dest_param); } else - file_param->copy(dest_param); + scr_param->copy(dest_param); } - filecopymovecomplete = true; } else{ // adjust destination fname to avoid conflicts (append "_", preserve extension) - fname = Glib::ustring::compose("%1%2%3%4%5",fname_noExt,"_",i_copyindex,".",fname_Ext); + Glib::ustring dest_fname = Glib::ustring::compose("%1%2%3%4%5",fname_noExt,"_",i_copyindex,".",fname_Ext); // re-construct destination File Paths - destfPath = dest_Dir + "/" + fname; - destfPath_param= destfPath + paramFileExtension; + dest_fPath = Glib::build_filename (dest_Dir, dest_fname); + dest_fPath_param= dest_fPath + paramFileExtension; i_copyindex++; } }//while