GSoC: Copy, Cut, and Paste Shared Files in ownCloud
As usual I ran into a couple more issues this past week that prevented me from completing many of the items on my Todo list. I also forgot to finish a couple of things like copying files, because it isn’t part of the web frontend.
First, I’d like to take some time responding to Lukas’s comment to last week’s post. I’ve spent a while debating whether or not to store all file records in the database or continue with the current solution with only recording folders and any files that differ compared to their parent folder. I’ve decided that it is best to stick with current solution because ownCloud isn’t designed nor wants to support a large number of users, but only small groups. Lukas also suggested some additional permissions or rules instead of the current read or write. Well, protected files are what every user has in their own directory. Private files with links are what the public link app can already do using a token for the link. Eventually this will be part of sharing files and offer the same functionality in one interface. Shared files right now are pulled directly out of the owner’s file system, but you have limited power when dealing with those files and can’t physically delete them, only unshare the files from yourself. Creating copies of the files would require a huge rewrite and it doesn’t seem to be worth the effort. If you’re still confused about how sharing files work and where your files are going please continue to ask questions.
Now, this past week figuring out how to copy files took a very long time and revealed many bugs along the way. I was using Dolphin and connected to ownCloud using WebDAV and I tried to copy a file from my shared directory that was actually my dummy user Bob’s file to my own filesystem root. Each time I received a 404 error, which didn’t make sense because ownCloud’s filesystem abstraction makes WebDAV see the same filesystem as the web frontend. I started logging the path translation occuring inside of the file_exists() function in the shared storage provider, and to my suprise the target and source path were the same. Turns out that I made a mistake during some of my previous testing in the database, which resolved the 404 error, but I shouldn’t be getting the same target back with my getSource() function. Yet again I had made another dumb mistake and forgotten to check if a variable was false before returning it as part of a string. This wasn’t the end of the bugs however, I still couldn’t copy files out of my shared directory and I wasn’t getting any errors in Dolphin now. Looking into my web server’s error log I discovered that there was an undefined variable inside of the local storage provider. The problem was a missing argument for the function fromTmpFile(). Now everything works perfectly and the good part is that this will benefit other storage providers because copying was broken when it was between two different storage providers.
I’m a little curious now why my IDE (Eclipse) or anyone else’s IDEs didn’t flag that line. There was clearly a problem because the function had two parameters and only one variable was passed to it. Is there something that I’m missing about PHP support in Eclipse because I thought problems were marked automatically? I like Eclipse because I’ve used it for Android development, but now I’m considering switching to something different that will actually help me out and show me the problems in the code. Does anyone have any IDE suggestions?
Back to my actual project, I now have copying and cutting of files working in and out of the shared directory with permission checks as well. Unfortunately WebDAV doesn’t notify Dolphin about the permissions it has for the files and folders. Usually the paste option in the right-click menu is disabled if I can’t write into a folder, but Dolphin tries to copy files anyways until the permission checks inside of the shared storage kick in and stop the copying. Is there a way to have WebDAV pass on this information and is there a way to have it provide image previews as well? I hope to finally start working on hooks and a basic user interface for sharing files within the web frontend this week. I’ll try my best this week to have a screenshot in the next post and instructions on how to help test!