- 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();