Fixed bug: Uploading a new version of a versioned file with no quota left would leave...
[pithos] / src / gr / ebs / gss / server / domain / FileHeader.java
index 2e74ca1..6523c94 100644 (file)
@@ -114,7 +114,7 @@ public final class FileHeader  implements Serializable{
         */\r
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "header")\r
        @OrderBy("version")\r
-       private List<FileBody> bodies;\r
+       private List<FileBody> bodies = new ArrayList<FileBody>();\r
 \r
        /**\r
         * The current (most recent) body of this file. The single one if not\r
@@ -358,6 +358,8 @@ public final class FileHeader  implements Serializable{
                if (body.getHeader() != null)\r
                        throw new IllegalArgumentException("Trying to add a FileBody that already belongs to a FileHeader.");\r
 \r
+               // Set child in parent\r
+               getBodies().add(body);\r
                // Set parent in child\r
                body.setHeader(this);\r
 \r
@@ -522,5 +524,17 @@ public final class FileHeader  implements Serializable{
                        throw new RuntimeException(e);\r
                }\r
        }\r
+\r
+       /**\r
+        * Return the total space occupied by this file in storage\r
+        * (i.e. the total size of all bodies)\r
+        * @return long\r
+        */\r
+       public long getTotalSize() {\r
+               long total = 0;\r
+               for (FileBody body: getBodies())\r
+                       total += body.getFileSize();\r
+               return total;\r
+       }\r
 }\r
 \r