Dear Uncle Cheese..
I too was afflicted by the duplicate folder bug and eventually traced it to this code in ImageGalleryPage.php :
function checkFolder() {
if( ! $this->RootFolderID ) {
$galleries = Folder::findOrMake('image-gallery');
$galleries->Title = 'Image Gallery';
$galleries->write();
$folder = Folder::findOrMake('image-gallery/' . $this->URLSegment);
$folder->Title = $this->Title;
$folder->setName($this->Title);
$folder->write();
$this->RootFolderID = $folder->ID;
$this->write();
$this->requireDefaultAlbum();
FormResponse::add( "\$( 'Form_EditForm' ).getPageFromServer( $this->ID );" );
}
else {
$this->RootFolder()->setName($this->Title);
$this->RootFolder()->write();
}
}
The $this->write() seems very often to not write the actual root folder under image-gallery/ but some other spurious folder number. I have not found the cause of that yet but it does not seem to matter what the number is although if it is wrong it will create an apparent "Gallery" (or whatever your page name is) folder in the root of the assets list in the Files & Images tab. It does not create a filesystem folder. If one manually sets the entry in the ImageGalleryPage table to the correct folder ID then all becomes well.
So the first question is what is the RootFolderID for? Other than the creation of spurious virtual directories if it is wrong it appears to have no other effect. I will investigate.
The second and MUCH bigger question is that I believe the entire gallery works backwards. We spend ages building up a filesystem and database of images which is easily damaged and not rebuilt using /dev/tasks/FilesystemSyncTask, whereas actually executing that function builds the ImageGallery image database in the Files & Images Folder anyway. So we wind up during development and testing with galleries we can see in Files & Images but can't use!
So why not change the ImageGallery so that when creating a new gallery we just point it to a Files & Images folder we have already created (and perhaps enabling us to add some more). Use the captions already provided. This stops reinventing the wheel so to speak and means the whole thing is far more bulletproof and self repairing than it is now where there is a separate and fairly fragile database. Indeed you could ftp images up there do a /dev/task and whammy the gallery would have them. Even the upgrade path for existing galleries would be simple.
I shall be working on this when I have time and post it.