X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fwamblee%2Fphotos%2Fmodel%2Ffilesystem%2FFileSystemAlbum.java;h=011381bf04cc04fa5293c12b6b92d0f6d3f0aeb7;hb=5f23cf9f2efbf7c8263931df8bb98d7148b790aa;hp=fcf4695311ae4e1ea4a03e0f6a0abe37ea31e530;hpb=ef7b3a22a3084312fe10a973b740f3ff35601870;p=photos diff --git a/src/main/java/org/wamblee/photos/model/filesystem/FileSystemAlbum.java b/src/main/java/org/wamblee/photos/model/filesystem/FileSystemAlbum.java index fcf4695..011381b 100644 --- a/src/main/java/org/wamblee/photos/model/filesystem/FileSystemAlbum.java +++ b/src/main/java/org/wamblee/photos/model/filesystem/FileSystemAlbum.java @@ -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(); } }