Changeset 6175


Ignore:
Timestamp:
2003-12-08T17:08:03+13:00 (20 years ago)
Author:
jmt12
Message:

When deleting FileNode.size() and get() are used instead of getChildCount() and getChildAt(), which had previously lead to a problem with filtered children

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r5847 r6175  
    121121    FileJob job = new FileJob(id, source, child, target, parent, type, undo, undoable);
    122122    job.folder_level = folder_level;
    123     ///ystem.err.println("Adding job: " + job);
     123        Gatherer.println("Adding job: " + job);
    124124    if(position != -1 && position <= queue.size() + 1) {
    125125        queue.add(position, job);
     
    413413                    // we just retrieve the metadata attached to the origin node...
    414414                    ArrayList existing_metadata = gdm.getMetadataOnly(source_file);
    415                     //Gatherer.println("Existing metadata for " + origin_node + ": " + gdm.toString(existing_metadata));
     415                    ///atherer.println("Existing metadata for " + origin_node + ": " + gdm.toString(existing_metadata));
    416416                    // then assign this remainder to the new folder.
    417417                    ///ystem.err.println("New metadata: " + gdm.toString(existing_metadata));
     
    441441            // If we haven't been cancelled, and we've been asked to delete a directory/file, or perhaps as part of a move, we delete the file. This involves removing any existing metadata and then copying the file to the recycled bin (for a delete only), then deleting the file. When deleting a directory record from the tree (or from the filesystem for that matter) we must ensure that all of the descendant records have already been removed. If we fail to do this the delete will fail, or you will be bombarded with hundreds of 'Parent node of null not allowed' error messages. Also be aware that if the user has cancelled just this action, because of say a name clash, then we shouldn't do any deleting of any sort dammit.
    442442            if(!cancel_action && ready && (job.type == FileJob.DELETE || job.type == FileJob.MOVE)) {
    443             ///ystem.err.print("Delete/Move: " + origin_node + " -> ");
     443            ///atherer.println("Delete/Move: " + origin_node);
     444            ///atherer.println(queue.size() + " jobs remain in queue");
    444445            // If the source is an empty directory or a file. Don't do anything to the root node of a tree.
    445446            File[] child_list = source_file.listFiles();
    446447            if(source_file.isFile() || (child_list != null && (child_list.length == 0 || (child_list.length == 1 && child_list[0].getName().equals(Utility.METADATA_XML))) && origin_node.getParent() != null)) {
    447                 ///ystem.err.println("File or empty directory.");
     448                ///atherer.println("File or empty directory.");
    448449                // Delete any metadata.xml still in the directory.
    449450                if(child_list != null && child_list.length == 1) {
     
    451452                }
    452453
    453                 ///ystem.err.println("Origin is file or is directory and is empty.");
     454                ///atherer.println("Origin is file or is directory and is empty.");
    454455                // update status area
    455456                String args[] = new String[1];
     
    471472                FileNode parent_record = (FileNode)origin_node.getParent();
    472473                // Remove from model
    473                 SynchronizedTreeModelTools.removeNodeFromParent(source_model, origin_node);
     474                if(parent_record != null) {
     475                SynchronizedTreeModelTools.removeNodeFromParent(source_model, origin_node);
     476                }
    474477                // If we are deleting
    475478                File recycled_file = null;
     
    526529            else if(child_list != null && child_list.length > 0) {
    527530                ///ystem.err.print("Nonempty directory -> ");
    528                 ///ystem.err.println("Directory is non-empty. Remove children first.");
     531                ///atherer.println("Directory is non-empty. Remove children first.");
    529532                FileNode recycle_folder_record = null;
    530533                // Don't worry about all this for true file move actions.
     
    555558                   origin_node.unmap();
    556559                   origin_node.map();
    557                    ///ystem.err.println("Directory has " + origin_node.getChildCount() + " children.");
    558                 ///ystem.err.println("Directory actually has " + child_list.length + " children.");
    559                   for(int i = 0; i < origin_node.getChildCount(); i++) {
    560                      FileNode child_record = (FileNode) origin_node.getChildAt(i);
    561                      addJob(job.ID(), job.source, child_record, job.target, destination_node, FileJob.DELETE, job.undo, false, false, position);
    562                      //if(recycle_folder_record != null) {
    563                      // recycle_folder_mappings.put(child_record, recycle_folder_record);
    564                      //}
    565                   }
    566                  
     560                   ///atherer.println("Directory has " + origin_node.getChildCount() + " children.");
     561                   ///atherer.println("Directory actually has " + child_list.length + " children.");
     562                   for(int i = 0; i < origin_node.size(); i++) {
     563                   FileNode child_record = (FileNode) origin_node.get(i);
     564                   ///atherer.println("Queuing: " + child_record);
     565                   addJob(job.ID(), job.source, child_record, job.target, destination_node, FileJob.DELETE, job.undo, false, false, position);
     566                   //if(recycle_folder_record != null) {
     567                   //   recycle_folder_mappings.put(child_record, recycle_folder_record);
     568                   //}
     569                   } 
    567570                }
    568571                // Requeue a delete job -after- the children have been dealt with. Remember I've reversed the direction of the queue so sooner is later. Te-he. Also have to remember that we have have followed this path to get here for a move job: Copy Directory -> Queue Child Files -> Delete Directory (must occur after child files) -> Queue Directory.
    569572                // One special case. Do not requeue root nodes. Don't requeue jobs marked as done.
    570573                if(origin_node.getParent() != null && !job.done) {
    571                 System.err.println("Requeuing: " + origin_node.getFile().getAbsolutePath());
     574                ///atherer.println("Requeuing: " + origin_node.getFile().getAbsolutePath());
    572575                job.type = FileJob.DELETE; // You only requeue jobs that are deletes, as directories must be inspected before children, but deleted after.
    573576                addJob(job, position);
    574577                }
    575578                else {
    576                 System.err.println("I've already done this job twice. I refuse to requeue it again!!!");
     579                Gatherer.println("I've already done this job twice. I refuse to requeue it again!!!");
    577580                }
    578581            }
     
    681684        // Check if the origin file exists.
    682685        if(!source.exists()) {
    683         System.err.println("Couldn't find the source file.");
     686        Gatherer.println("Couldn't find the source file.");
    684687        throw(new FileNotFoundException());
    685688        }
Note: See TracChangeset for help on using the changeset viewer.