jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (JCR-1394) FileDataStore Garbage Collector and empty directories
Date Fri, 22 Feb 2008 19:01:19 GMT

     [ https://issues.apache.org/jira/browse/JCR-1394?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jukka Zitting resolved JCR-1394.
--------------------------------

    Resolution: Fixed
      Assignee: Jukka Zitting

Good idea! Automatic directory removal added in revision 630285.

I used a slightly different mechanism that doesn't need multiple passes and that avoids accidentally
removing the root directory of the data store:

    if (file != directory && file.list().length == 0) {
        file.delete();
    }

> FileDataStore Garbage Collector and empty directories
> -----------------------------------------------------
>
>                 Key: JCR-1394
>                 URL: https://issues.apache.org/jira/browse/JCR-1394
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Jacco van Weert
>            Assignee: Jukka Zitting
>            Priority: Minor
>             Fix For: 1.5
>
>   Original Estimate: 0.17h
>  Remaining Estimate: 0.17h
>
> 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