Creating folders is now working.
[photos] / src / main / java / org / wamblee / photos / model / filesystem / FileSystemAlbum.java
index fcf4695311ae4e1ea4a03e0f6a0abe37ea31e530..011381bf04cc04fa5293c12b6b92d0f6d3f0aeb7 100644 (file)
@@ -496,28 +496,32 @@ public class FileSystemAlbum implements Album {
      * @see org.wamblee.photos.database.Album#addAlbum(java.lang.String)
      */
     public void addAlbum(String aId) throws IOException {
-        PhotoEntry entry = find(aId);
-        if (entry != null) {
-            throw new IOException("Entry already exists in album " + getId() +
-                    " : " + aId);
-        }
-        // Entry not yet found. Try to create it.
-        File albumDir = new File(_dir, aId);
-        if (!albumDir.mkdir()) {
-            throw new IOException("Could not create album: " + aId);
-        }
-        File photosDir = new File(albumDir, PHOTOS_DIR);
-        if (!photosDir.mkdir()) {
-            throw new IOException("Could  not create photo storage dir: " + photosDir.getPath());
-        }
-        File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
-        if (!thumbnailsDir.mkdir()) {
-            throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+        try {
+            PhotoEntry entry = find(aId);
+            if (entry != null) {
+                throw new IOException("Entry already exists in album " + getId() +
+                        " : " + aId);
+            }
+            // Entry not yet found. Try to create it.
+            File albumDir = new File(_dir, aId);
+            if (!albumDir.mkdir()) {
+                throw new IOException("Could not create album: " + aId);
+            }
+            File photosDir = new File(albumDir, PHOTOS_DIR);
+            if (!photosDir.mkdir()) {
+                throw new IOException("Could  not create photo storage dir: " + photosDir.getPath());
+            }
+            File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
+            if (!thumbnailsDir.mkdir()) {
+                throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+            }
+            String newPath = _path + "/" + aId;
+            newPath = newPath.replaceAll("//", "/");
+            FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
+            addEntry(album);
+        } finally {
+            _entries.invalidate();
         }
-        String newPath = _path + "/" + aId;
-        newPath = newPath.replaceAll("//", "/");
-        FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
-        addEntry(album);
     }
 
     /*
@@ -526,16 +530,20 @@ public class FileSystemAlbum implements Album {
      * @see org.wamblee.photos.database.Album#removeAlbum(java.lang.String)
      */
     public void removeEntry(String aId) throws IOException {
-        PhotoEntry entry = find(aId);
-        if (entry == null) {
-            throw new IOException("Entry " + aId + " not found.");
-        }
-        if (entry instanceof FileSystemAlbum) {
-            // album.
-            removeAlbum((FileSystemAlbum) entry);
-        } else {
-            // regular photo
-            removePhoto(entry);
+        try {
+            PhotoEntry entry = find(aId);
+            if (entry == null) {
+                throw new IOException("Entry " + aId + " not found.");
+            }
+            if (entry instanceof FileSystemAlbum) {
+                // album.
+                removeAlbum((FileSystemAlbum) entry);
+            } else {
+                // regular photo
+                removePhoto(entry);
+            }
+        } finally {
+            _entries.invalidate();
         }
     }