Skip to content

if we read a .part file we try to get the file info from the real file - #11736

Merged
schiessle merged 3 commits into
masterfrom
enc_get_fileinfo_from_real_file
Nov 7, 2014
Merged

schiessle merged 3 commits into
masterfrom
enc_get_fileinfo_from_real_file

Conversation

@schiessle

Copy link
Copy Markdown
Contributor

if we read a .part file we try to get the file info from the real file.

fix issue discussed here #11659 (comment)

This makes sure that we don't try to calculate the unencrypted size from part files during upload.

cc @DeepDiver1975 @jknockaert please review, thanks!

@schiessle schiessle mentioned this pull request Oct 23, 2014
@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn No this doesn't work. The condition $view->file_exists($realPath) can't be met because before the rename there's no file at $realPath (and after the rename there's no partFile left). You should check if the record exists in the filecache (not sure if there's a procedure for this). But even then it could fail: as I pointed out in #11659 there's a subsequent getFileSize call (after renaming the file) which happens because there's no filecache for $realPath. So I'm not sure at all if the filecache for $realPath is removed before the rename or if it wasn't created at all.
Also don't forget to save the proxyState before disabling it.

@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert it works if you update a file, this is what I tested previously. But it doesn't work for new files, you are right. I currently working on it. The problem, if we close the stream we write the file cache entry for the real file with the unencrypted size. But it seems like the file cache doesn't accept it, probably because the file doesn't exists.

Probably we need to remember the values in a property, take it from there in the getFileSize call and write it to the file cache after the file was renamed.

@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn I think you are right. I was just monitoring filecache sql, and it doesn't set the encryption bit nor the encrypted_size upon stream_close. I don't yet understand why.

@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn Alright, I've been debugging. This is what happens. Upon putFileInfo in stream_close it will find out that not all required fileinfo is submitted: https://github.com/owncloud/core/blob/master/lib/private/files/cache/cache.php#L227 So it stores the fileinfo in memory rather than database. So far so good. When doing getFileInfo in postFileSize it should get back the partial info; there's provision to do so here https://github.com/owncloud/core/blob/master/lib/private/files/cache/cache.php#L114 But it doesn't work, basically because getFileInfo calls inCache before reading the cache: https://github.com/owncloud/core/blob/master/lib/private/files/view.php#894 The inCache procedure fails because it only checks the database using getId: https://github.com/owncloud/core/blob/master/lib/private/files/cache/cache.php#L357 (getId can't reasonably return anything meaningful for in-memory cache). So inCache should be extended with isset($this->partial[$file])
But even after patching inCache, it still doesn't work. The partial in-memory cache is set upon stream_close, but fails to be returned upon getFileInfo in postFileSize. And I don't understand why. Maybe a namespace issue?

@jknockaert

Copy link
Copy Markdown
Contributor

I also observed that the (encrypted) file size submitted by stream_close is different from what is determined by the scanner when it is invoked by getFileSize. The difference is not constant (so it is not the size of the encryption header). Is there a reason stream_close has to submit a file size? Only the unencrypted size matters I would say...

@schiessle

Copy link
Copy Markdown
Contributor Author

Great work @jknockaert ! Today I will also have a look at it, maybe I can fix it.

Is there a reason stream_close has to submit a file size? Only the unencrypted size matters I would say...

Good question. I don't remember why it was added in the past. But I think you are right and we can remove it. The file cache should take care of it.

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from 771b95f to cc68172 Compare October 27, 2014 10:56
@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert I pushed some changes, this should work. I think the problem was, that we are calling different instances of the cache class here. In order to have the information across instances $partial needs to be static.

@icewind1991 Please have a look, does it make sense?

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from cc68172 to 8fcdc96 Compare October 27, 2014 11:16
Comment thread lib/private/files/cache/cache.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should add some brackets for readability

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from 8fcdc96 to 63eec2c Compare October 27, 2014 11:55
@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert I added the 'size' again and additionally 'mtime' and 'mimetype' because this are required values. This was probably also the reason while 'size' was set in the past, though I don't know why the other two values wasn't there. Maybe this requirement was introduced later...

Comment thread lib/private/files/cache/cache.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause issues if multiple storages have files with the same path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what we could do to prevent it and still fix the issue?

Maybe we can add the storage as additional identifier to the array?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the changes in this PR require this to be static

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that at this point we write the file info: https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/stream.php#L641. But we always write it for the real file, not the part file which was written at this point in time. That's not a problem if the original file already exists because then the existing file cache entry gets updated. But if a new file was uploaded, then the original file doesn't exists yet.

Here we ask for the file size to verify that the complete file was uploaded https://github.com/owncloud/core/blob/master/lib/private/connector/sabre/file.php#L110. To make the check work we need the unencrypted size, but it is not in the database, because the target file doesn't exists yet. Therefore we need the value from $partial. But at this point we no longer operate on the same instance of the cache class like we did when we updated the $partial array. That's why I made it static. To have this information across multiple instances of the class cache. Hope I could explain the reason behind it. I'm open for other solution, but right now I can't think about one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But at this point we no longer operate on the same instance of the cache class like we did when we updated the $partial array

That seems like a bug, making it static will work around it but wont fix the underlying bug.
That may be fixed with #11539 do you have the time to test that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will have a look at it. Would be great if it would fix the issue!

@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn Ok for the size attribute, but I observed that the value submitted at stream_close is different from the one registered in the database in the subsequent getFileSize.

@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert Yes, I keep this in mind. Let's try to find out why it happens, maybe because of the header as you already assumed.

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from 63eec2c to 5b7ace5 Compare October 27, 2014 15:46
@schiessle

Copy link
Copy Markdown
Contributor Author

The last commit should pass all unit tests. To avoid confusions between similar paths on different storages I grouped the paths along the storage ID in $partial. @icewind1991 please have a look at it, thanks!

@schiessle

Copy link
Copy Markdown
Contributor Author

Seems that #11539 solves this issue to a large extend. Let's wait until it is merged and then base this PR on the new master with the small changes to encryption and the changes to inCache() (https://github.com/owncloud/core/pull/11736/files#diff-ca0134427283e74d6b21c7e366ff48e5R355)

@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn Ok, so after #11539 is merged we will fix this one. And after that I will rework #8390. Any indication of the time horizon?

@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert I hope #11539 will go in soon. I think we just need to fix the failing unit tests. Then it should be fast to get this fix in so that you can rework #8390.

In the mean time we can already finish #11659, right? The problem here is independent from it.

@jknockaert

Copy link
Copy Markdown
Contributor

@schiesbn Yes we can finish #11659. There's no reproducible errors that I know of, the code is pretty clean, so I consider it ready for review.

@schiessle

Copy link
Copy Markdown
Contributor Author

I just updated this PR. This should work in combination with #11539, will rebase as soon as the other PR is merged for some final testing and reviewing

@LukasReschke

Copy link
Copy Markdown
Contributor

#11882?

@schiessle

Copy link
Copy Markdown
Contributor Author

@LukasReschke sorry, had the wrong number in my clipboard... 😄 I updated my comment, correct is #11539

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from fbb28f1 to 25628c6 Compare October 31, 2014 09:54
@schiessle

Copy link
Copy Markdown
Contributor Author

#11539 was merged, this branch is rebased and tested... Everything looks good!

This is now ready to review. @icewind1991 @jknockaert please have a look at it, thanks!

@schiessle

Copy link
Copy Markdown
Contributor Author

@jknockaert locally all tests passed, so I'm confident that they are OK once Jenkins manages to finish them without a internal error

@ghost

ghost commented Nov 3, 2014

Copy link
Copy Markdown

💣 Test FAILed. 💣
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/1813/

Build result: ABORTED

GitHub pull request #11736 of commit ff26037 automatically merged.Building remotely on vm-slave-02 (SLAVE) in workspace /var/jenkins/workspace/pull-request-analyser-ng-simple > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url https://github.com/owncloud/core.git # timeout=10Fetching upstream changes from https://github.com/owncloud/core.git > git --version # timeout=10 > git fetch --tags --progress https://github.com/owncloud/core.git +refs/pull/:refs/remotes/origin/pr/ > git rev-parse origin/pr/11736/merge^{commit} # timeout=10Checking out Revision 54c8e2d3efe1edf81c7fefb3e557c9f4d4f7b9f8 (detached) > git config core.sparsecheckout # timeout=10 > git checkout -f 54c8e2d3efe1edf81c7fefb3e557c9f4d4f7b9f8 > git rev-list 842d9e419205bdbba0410bbfa3fbaf768f5cbeef # timeout=10 > git remote # timeout=10 > git submodule init # timeout=10 > git submodule sync # timeout=10 > git config --get remote.origin.url # timeout=10 > git submodule update --init --recursiveTriggering pull-request-analyser-ng-simple » vm-slave-02pull-request-analyser-ng-simple » vm-slave-02 appears to be cancelledpull-request-analyser-ng-simple » vm-slave-02 completed with result ABORTEDStarted calculate disk usage of buildFinished Calculation of disk usage of build in 0 secondsStarted calculate disk usage of workspaceFinished Calculation of disk usage of workspace in 1 second
💣 Test FAILed. 💣

@schiessle

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@ghost

ghost commented Nov 3, 2014

Copy link
Copy Markdown

🚀 Test PASSed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/1814/
🚀 Test PASSed. 🚀

@jknockaert

Copy link
Copy Markdown
Contributor

Ok, this PR changed quite a bit compared to its initial version. I'm not sure if I fully oversee the extent of the changes. Initially the idea was to never store .part file information in the cache but rather register it immediately for the correct file. It was implemented as such in stream.php, and util.php was updated consistent with this. That should've worked. After rebase it is now reversed to basically an update of stream.php to submit the information for both the .part file and the correct file, as well as small supporting changes to proxy.php and view.php (the proposed changes to cache.php seem purely cosmetic to me). I'm not sure if I fully understand the purpose of the .part files. I'm just wondering why they need a special treatment in stream.php. Shouldn't the update in the filecache upon renaming from .part to correct file be triggered by a rename hook? And why don't we need an update of inCache anymore?

@schiessle

Copy link
Copy Markdown
Contributor Author

if I fully understand the purpose of the .part files. I'm just wondering why they need a special treatment in stream.php. Shouldn't the update in the filecache upon renaming from .part to correct file be triggered by a rename hook? And why don't we need an update of inCache anymore?

Let me try to explain the problem: When we write the information to the real file name (without the .part extension) the file cache will try to scan the file during the read operation. Which will result in some errors and warnings in your ownCloud log because $partial indicates that there should be a file but actually it doesn't exists. On the other hand .part files are ignored by the file cache.

Because the webdav code also ask for the size of the .part file to verify that the complete file was uploaded I decided to skip the extra steps of stripping the .part away and just check for the .part file and write this information also to partial. This way we avoid quite some extra code to handle the part file. Because ownCloud ignores .part files we also avoid any errors in the owncloud.log, that's also the reason why we can't move the file info from the .part file to the real file during rename. .Part files never get written to the file cache and we don't trigger any hooks for them.

@jknockaert

Copy link
Copy Markdown
Contributor

Ok. I noticed that view.php has been modified in another PR so there's no call to inCache anymore in that part of the code.
I am however not sure how you get around the scanner errors when we write file information to the cache at the end of stream.php both for the .part file and for the real file (which doesn't exist). From that moment on $partial indicates that the real file should be there, right?

@schiessle

Copy link
Copy Markdown
Contributor Author

we write file information to the cache at the end of stream.php both for the .part file and for the real file (which doesn't exist).

The scanner only gets called if I ask for the information, because then he tries to complete it. The webdav code only ask for the .part file. The warinings happened in the past because we stripped the .part away and asked for the fileinfo of the real file while now we can stay on the .part file.

@jknockaert

Copy link
Copy Markdown
Contributor

Ok, I misunderstood how the scanner was triggered. I guess the change in view.php is to avoid running checkUpdate on a .part file. Altogether this seems to me to be a quite smart implementation.

@schiessle

Copy link
Copy Markdown
Contributor Author

I guess the change in view.php is to avoid running checkUpdate on a .part file.

Yes, because in all other areas we also ignore .part files.

Also if you compare the changes from the current pull request with the changes we had before the diff is quite small now. A lot of extra handling is gone now.

Comment thread apps/files_encryption/lib/stream.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test it, but I just wondered if you need a new view here. Can't you use $this->rootView further down at line 636?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch... fixed in one second 😉

@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from ff26037 to c8a1929 Compare November 7, 2014 12:20
@ghost

ghost commented Nov 7, 2014

Copy link
Copy Markdown

🚀 Test PASSed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/2367/
🚀 Test PASSed. 🚀

@jknockaert

Copy link
Copy Markdown
Contributor

I guess this one is ready to be merged now, right?

@schiessle

Copy link
Copy Markdown
Contributor Author

We need two reviewer... If you say it is OK I count you as one so we need a second one... @PVince81 or @LukasReschke maybe?

@jknockaert

Copy link
Copy Markdown
Contributor

Having reviewed the code (but not tested) I say it is OK.

@LukasReschke

Copy link
Copy Markdown
Contributor

I'll test this.

Bjoern Schiessle added 3 commits November 7, 2014 15:17
… for both

the real file and the part file, because some information from the part file
might be needed later
@schiessle
schiessle force-pushed the enc_get_fileinfo_from_real_file branch from c8a1929 to 2af7256 Compare November 7, 2014 14:22
@schiessle

Copy link
Copy Markdown
Contributor Author

rebased to resolve merge conflicts

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 6 updated code elements

@LukasReschke

Copy link
Copy Markdown
Contributor

👍

@ghost

ghost commented Nov 7, 2014

Copy link
Copy Markdown

🚀 Test PASSed. 🚀
Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/2380/
🚀 Test PASSed. 🚀

schiessle added a commit that referenced this pull request Nov 7, 2014
if we read a .part file we try to get the file info from the real file
@schiessle
schiessle merged commit 68a522a into master Nov 7, 2014
@schiessle
schiessle deleted the enc_get_fileinfo_from_real_file branch November 7, 2014 15:20
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants