Changeset 34261


Ignore:
Timestamp:
2020-07-11T08:00:38+12:00 (4 years ago)
Author:
ak19
Message:
  1. Fixed the bug with GLI's Gather Rightclick > Replace when the replacement file and the file being replaced had the same name. Things mostly worked, including in the remote case: when the filenames were the same or different, the files would get correctly transferred, retaining meta, to the remote GS. But if the files were the same name, then in (client)GLI the file ends up lost unless it's client-GLI, in which case reopening the collection transferred the correct new file across with meta. This bugfix ensures that nothing is lost in GLI or client-GLI and that no reopening of client-GLI is necessary to fix it. The final fix ended up far easier than all my initial ways of solving it which failed to work (like renaming the src file temporarily while copying the identically named target across). 2. DebugStream error msg visibility can now be toggled on and off and prints START DEBUGGING to END DEBUGGING messages with caller name for the section of code where it's toggled on. This came in handy when debugging this time, so leaving it in for future use.
Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/DebugStream.java

    r31692 r34261  
    5757    }
    5858
     59
     60    static public void setDebugging(boolean isEnabled, String caller) {
     61    if(isEnabled) {
     62        System.err.println("**** START DEBUGGING (enabled by: " + caller + ")");
     63    } else {
     64        System.err.println("**** END DEBUGGING (called by: " + caller + ")");
     65    }
     66    debugging_enabled = isEnabled;
     67    }
    5968
    6069    static synchronized public boolean isDebuggingEnabled()
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java

    r22605 r34261  
    5353import org.greenstone.gatherer.util.DragComponent;
    5454import org.greenstone.gatherer.util.Utility;
     55import org.greenstone.gatherer.DebugStream;
    5556
    5657/** Manages the moving of files within a separate thread.
     
    546547        WorkspaceTreeNode source_node = new WorkspaceTreeNode(new_file);
    547548
     549        //DebugStream.setDebugging(true, "FileManager.ReplaceTask");
     550
     551        // Some different handling if the old and new tail file names are the same and target file goes into the same
     552        // location in collection tree as source.
     553        // This avoids past errors upon replacing with same filename (diff file contents) where the attached meta gets lost,
     554        // or remote file gets updated but file gone missing in client-GLI view until collection reopened.
     555        boolean isSameLeafName = false;
     556        if(collection_tree_node.getFile().getName().equals(new_file.getName())) {
     557        DebugStream.println(" @@@ File Replace: New file has the same name as existing.");
     558        isSameLeafName = true;
     559        }
     560       
    548561        File target_directory = collection_tree_node.getFile().getParentFile();
    549562        CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new File(target_directory, new_file.getName()));
    550         // copy the new file in - but don't bring metadata
    551         file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(),  FileJob.COPY_FILE_ONLY);
     563       
     564        FileNode parent = (FileNode)collection_tree_node.getParent(); // store the original source's parent, need it several times after changing source
     565       
     566        if(!isSameLeafName) {
     567        // If the file name of the replacing file is NOT the same as the one being replaced
     568        // copy the new file in - but don't bring metadata
     569        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY);
     570        }
     571       
    552572        if (Gatherer.isGsdlRemote) {
    553573        String collection_name = CollectionManager.getLoadedCollectionName();
     
    555575        Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory);
    556576        }
    557         // do a replace of old file with new file
    558         file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
     577
     578        if(isSameLeafName) {
     579        // If the file name of the replacing file IS the same as the one being replaced
     580        // perform a COPY operation, which will copy across metadata too, after confirming whether the user really wants to replace the source with identically named targed
     581        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY);
     582        } else {
     583        // If the file name of the replacing file is NOT the same as the one being replaced, final step to finish off:
     584        // do a replace of old file with new file
     585        file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
     586        }
     587
     588        //DebugStream.setDebugging(false, "FileManager.ReplaceTask");
     589
    559590    }
    560591    }
Note: See TracChangeset for help on using the changeset viewer.