On Tuesday 14 April 2009 19:17:30 saces at freenetproject.org wrote:
> Author: saces
> Date: 2009-04-14 18:17:30 +0000 (Tue, 14 Apr 2009)
> New Revision: 26787
> 
> Added:
>    trunk/freenet/src/freenet/support/ContainerSizeEstimator.java
> Log:
> helper class to estaminate container size 
> 
> Added: trunk/freenet/src/freenet/support/ContainerSizeEstimator.java
> ===================================================================
...
> +     
> +     private static void getSubTreeSize(HashMap<String, Object> metadata, 
ContainerSize result, long maxItemSize, long maxContainerSize,int maxDeep) {
> +             Set<String> set = metadata.keySet();
> +             // files
> +             for(String name:set) {
> +                     Object o = metadata.get(name);
> +                     if (o instanceof ManifestElement) {
> +                             ManifestElement me = (ManifestElement)o;
> +                             long itemsize = me.getSize();
> +                             if (itemsize > -1) {
> +                                     result._sizeFilesNoLimit += 
> getContainerItemSize(me.getSize());
> +                                     if (itemsize > maxItemSize)
> +                                             result._sizeFiles += 512;  // 
> spare for redirect

You have to count the tar block, the tar padding, and then the redirect as 
well. It might be more than this. See the comments in SimpleManifestPutter 
(which still gets it wrong sometimes).

> +                                     else
> +                                             result._sizeFiles += 
> getContainerItemSize(me.getSize());
> +                                     if (result._sizeFiles > 
> maxContainerSize) break;
> +                             }
> +                     }
> +             }
> +             // sub dirs
> +             if (maxDeep > 0) {
> +                     for(String name:set) {
> +                             Object o = metadata.get(name);
> +                             if (o instanceof HashMap) {
> +                                     result._sizeSubTrees += 512;
> +                                     @SuppressWarnings("unchecked")
> +                                     HashMap<String, Object> hm = 
> (HashMap<String, Object>) o;
> +                                     ContainerSize tempResult = new 
> ContainerSize();
> +                                     getSubTreeSize(hm, tempResult, 
> maxItemSize, 
(maxContainerSize-result._sizeSubTrees), maxDeep-1);
> +                                     result._sizeSubTrees += 
> tempResult.getSizeTotal();
> +                                     result._sizeSubTreesNoLimit += 
> tempResult.getSizeTotalNoLimit();
> +                                     if (result._sizeSubTrees > 
> maxContainerSize) break;
> +                             }
> +                     }
> +             }
> +     }
> +
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: This is a digitally signed message part.
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20090414/303cbdb4/attachment.pgp>

Reply via email to