Friday, 30 March 2007

MySource 4.0 WebDAV ideas

I've been thinking about how to implement some new features and improvements into the MySource 4.0 WebDAV server. All these changes would go in after the alpha release and user feedback, but I thought I'd try and list them in one place so I don't forget about them.

Adding new files and folders
The problem with adding (and deleting) files and folders is actually editing. That sounds a bit weird, so let me explain.

When you edit files, the application or file system decides on the process it will use to save the file. Most applications don't make things easy by using a simple LOCK then PUT (a new version) then UNLOCK. Most applications I test with move the current file and create temp files and directories before finally renaming a temp file to replace the existing file we are editing. This means that I get a lot of DELETE, MOVE, PUT and MKCOL requests coming through. If I actually processed all of these requests in the CMS, assets would be moving all over the place, and often being replaced by new assets with the same name while they end up in the trash.

To solve this problem, I don't action any of these request when asked. Instead, I keep a record of where files and folders should be. This allows me to pretend that files have been moved, created or deleted without having to actually do it. Then when a temp file is moved to the location of an existing file, I update the file's contents in the CMS.

That is a lot of background to basically say that I can never trust a PUT request. There is no way of knowing if it is a real request to create a new file or if it is just an application trying to save an existing file. Forget sessions and cookies to store information about what is going on. They are not supported in WebDAV.

So here is my idea. When someone drags a file into a folder, I pretend that it exists. I don't currently show that file in the folder, but I could. If I do show the file, I can also allow it to be edited. For users of WebDAV, it would appear that the file has been created in the CMS, but it really only exists in the WebDAV database. To commit the file to the CMS, a user could go to some location in MySource 4.0 and indicate that a pending WebDAV file should be turned into a real File asset.

Deleting existing files and folders
For the same reason as adding files and folders is a problem, deleting is a problem as well. There is no way to tell if the user deleted the file or if the application deleted it while saving.

In the same way that added files can be shown, deleted files can be hidden. In fact, I already do hide them because it causes OS X's Finder to go crazy if it thinks a file should be deleted but it is still there (fair enough I guess). Again, a user could go to a location in MySource 4.0 and indicate that files marked as deleted should be moved to the trash within the CMS.

Authentication and permissions
Forcing a user to authenticate before connecting to the WebDAV server is dead easy. However, you do need to re-authenticate every time a request is made because sessions (cookies) are not supported. That isn't a problem, but it is something to remember when this functionality is added.

Similarly, checking permissions on assets before displaying them is not going to be hard. Where I do see things getting a little interesting is the display of projects and project folders. They don't have any specific permissions applied to them, so who do we show them too? We could say that any user can see the projects in which their account exists, or we could say that they see projects where they can read at least one item in the project. The first method is quick, the second is slow. Unsurprisingly, I'm leaning towards the first option.

Temporary items on OS X
I noticed, completely by accident, that if I told Word on OS X that the Temporary Items folder didn't exist, it would save the file using less requests. The figures are something like 30 requests versus 22. Instead of moving temporary files around, it would just create backup copies in the same location as the existing file.

I do have support for the Temporary Items folder in the WebDAV server, but I'm wondering if taking out that support might actually improve performance on OS X. Word on Windows doesn't suffer from the same problem as it choses to save files differently (of course).

I'd like to do some testing to see if this could be a possible improvement to the WebDAV server.