Forum OpenACS Development: Changing Name and Title in File Storage

First of all, we should encourage people to test upgrade scripts on live system data so we detect any hickups in advance before releasing our software. Now for the real issue:

The file storage upgrade from 5.1.0a6 to 5.1.0a7 introduced a change that exchanged the name and the title of a file. After fixing the upgrade script with Dave for dotlrn.org yesterday, I realized (together with experience collected at Heidelberg's site) that we have a fundamental problem due to this switch.

Direct links to files are broken as long as you do not navigate to them using the file storage interface. Take this as an example:

http://dotlrn.org:8000/file-storage/view/images/screenshot-dotlrn-download.jpg used to work before the upgrade. As there were multiple versions of screenshot-dotlrn-download.jpg, the upgrade renamed them (as we have a unique constraint on name,parent_id in cr_items) by adding a counter. The new file is called therefore called screenshot-dotlrn-download.5.jpg (name) with the title screenshot-dotlrn-download.jpg (title). Title does not have to be unique !

But how can you access this file now? http://dotlrn.org:8000/file-storage/view/images/screenshot-dotlrn-download.5.jpg

As you can see, the URLs are different and obviously all pages that contain links to files in file storage (with multiple revisions before the upgrade) are broken.

My proposed solution to this:

Before marking a file as failed, check if there is not an item with the TITLE (instead of name) for the URL.

This has been done and tested briefly. Change made to the content::init function as follows:

# cache this query persistently for 1 hour set item_info(item_id) [::content::item::get_id -item_path $url \
-root_folder_id $content_root \
-resolve_index "f"]
# Make sure we are not dealing with an upgraded file and there exists a file with the title
if { [string equal "" $item_info(item_id)] } {
set splitted_url [split $url "/"]
set item_url_title [lindex $splitted_url end]
set item_url_folder [lindex $splitted_url end-1]
set item_info(item_id) [db_string test "select i.item_id
from cr_revisions r, cr_items i where r.item_id = i.item_id
and r.title = :item_url_title and i.parent_id = (select
item_id from cr_i\tems where name = :item_url_folder) order
by revision_id desc limit 1"]
}

If this solution is flawed, please state how and why. If noone complains I will commit this (with the db_query put into the .xql file) tomorrow morning. It fixed all issues at dotlrn.org with regards to files not being found with direct URLs and I think Heidelberg will be happy as well.

Collapse
Posted by Malte Sussdorff on
obviously -default "" was missing from db_string :).
Collapse
Posted by Malte Sussdorff on
I *strongly* recommend to change the default behaviour on content_folders to not only change the *label* but also the *name* of the folder if the folder is renamed, *OR* use the label to find the PATH for files in file storage. This will take care of #2157 and result in a decent consistency of the system itself.

Is there a use case where you change the label of a folder (aka what the user sees) but not the name (that is used for the URL). If there is, does this affect file-storage and WebDAV?

Unless someone complains (especially Dave), I will make the change to "label" instead of "name" for detecting the item_id of the folder in one go with the change above. Regardless of the answer of for the use case, I'd only make this change on folder-edit-2 in the file storage and leave it to others to fix it wherever they see the need (e.g. webdav).

Collapse
Posted by Dave Bauer on
Malte,

WHY do you want to change the folder URL? This would be a major design change to the content repository, and I can't see changing this.

Collapse
Posted by Dave Bauer on
Also,

The label is the "display name" of the folder. So it does not have to match the URL of the folder. I do not think the cr_items.name should ever change in most circumstances. That will result in broken links. Of course someone decided to add "pretty URLs" to file storage using the title instead of the filename for the URL which caused the confusing upgrade problem we have now.

Collapse
Posted by Dave Bauer on
Malte,

Are you proposing to change the file-storage/www/view/index.vuh file? I think this is fine and will help to resolve issues on the upgrade.

Collapse
Posted by Malte Sussdorff on
I guess all I've been suggesting is to make sure that when you click on "rename folder", the name of the folder is changed in addition to the label, so it behaves like a file system, which is what users suspect. To not break existing functionality add a "behave_like_filesystem_p" parameter (default "f") that controls all changes necessary to make file storage behave like a file system, e.g. renaming folders.
Collapse
Posted by Dave Bauer on
Malte, This sounds good. We want to make sure that when we change existing behavior that some users are not relying on that behavior, even if we think it might not be ideal. Allowing optional fall back to the original behavior is a good idea in this situation.
Collapse
Posted by Malte Sussdorff on
I added the parameter BehaveLikeFilesystemP on oacs-5-1. The first thing I did was modify index.vuh to deliver files (especially HTML Pages) without the OpenACS template if the parameter is set to 1. This allows you to upload your HTML content and display it just like in Dreamweaver or other tools of your choice.

Furthermore, if BehaveLikeFilesystemP is true, it will try to find files from the upgrade where the relative linking is broken. As this only affects sites where you assume FileStorage to behave like a file system, I think this is okay.

Obviously this needs more testing by power users, but I think it is working fine for the moment.

The default for BehaveLikeFilesystemP is true, but if the parameter is not set (e.g. after an upgrade), the beviour defaults to false. This means, if you upgrade, you still have the old behaviour but on a new installation File Storage actually behaves like a File System.

More on the todo list:

- Fix the folder issue.
- Allow upload of Compressed files and keep their internal folder structure.