jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacco van Weert (JIRA)" <j...@apache.org>
Subject [jira] Created: (JCR-1394) FileDataStore Garbage Collector and empty directories
Date Tue, 19 Feb 2008 08:20:43 GMT
FileDataStore Garbage Collector and empty directories
-----------------------------------------------------

                 Key: JCR-1394
                 URL: https://issues.apache.org/jira/browse/JCR-1394
             Project: Jackrabbit
          Issue Type: Improvement
    Affects Versions: 1.4
            Reporter: Jacco van Weert
            Priority: Minor
             Fix For: 1.5, 1.4


When the org.apache.jackrabbit.core.data.GarbageCollector is called for a FileDataStore the
file objects are correctly deleted.
But the (sub)directories aren't removed.
In time this will result in a huge tree of unused empty directories

I've created a small chance in method FileDataStore.deleteOlderRecursive()
It will remove a directory when it hasn't any files entries. Please note that currently the
file objects are stored three levels deep, so it
will take three gc calls remove all directories. Which I think is no problem because the currently
implementation is lightweighted.

>>>>> CURRENT FileDataStore.java

    private int deleteOlderRecursive(File file, long min) {
        int count = 0;
        if (file.isFile() && file.exists() && file.canWrite()) {
            if (file.lastModified() < min) {
                DataIdentifier id = new DataIdentifier(file.getName());
                if (!inUse.containsKey(id)) {
                    file.delete();
                    count++;
                }
            }
        } else if (file.isDirectory()) {
            File[] list = file.listFiles();
            for (int i = 0; i < list.length; i++) {
                count += deleteOlderRecursive(list[i], min);
            }
        }
        return count;
    }

>>>>>>> NEW

    private int deleteOlderRecursive(File file, long min) {
        int count = 0;
        if (file.isFile() && file.exists() && file.canWrite()) {
            if (file.lastModified() < min) {
                DataIdentifier id = new DataIdentifier(file.getName());
                if (!inUse.containsKey(id)) {
                    file.delete();
                    count++;
                }
            }
        } else if (file.isDirectory()) {
            File[] list = file.listFiles();
            if (list.length==0) {
              file.delete();
            } else {
              for (int i = 0; i < list.length; i++) {
                count += deleteOlderRecursive(list[i], min);
              }
            }
        }
        return count;
    }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message