Repository navigation
if we read a .part file we try to get the file info from the real file - #11736
Conversation
|
@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. |
|
@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. |
|
@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. |
|
@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]) |
|
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... |
|
Great work @jknockaert ! Today I will also have a look at it, maybe I can fix it.
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. |
771b95f to
cc68172
Compare
|
@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? |
cc68172 to
8fcdc96
Compare
There was a problem hiding this comment.
maybe you should add some brackets for readability
8fcdc96 to
63eec2c
Compare
|
@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... |
There was a problem hiding this comment.
This will cause issues if multiple storages have files with the same path
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I'm not sure how the changes in this PR require this to be static
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Sure, I will have a look at it. Would be great if it would fix the issue!
|
@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. |
|
@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. |
63eec2c to
5b7ace5
Compare
|
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! |
|
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 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. |
|
@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. |
5b7ace5 to
fbb28f1
Compare
|
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 sorry, had the wrong number in my clipboard... 😄 I updated my comment, correct is #11539 |
fbb28f1 to
25628c6
Compare
|
#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! |
|
@jknockaert locally all tests passed, so I'm confident that they are OK once Jenkins manages to finish them without a internal error |
|
💣 Test FAILed. 💣 Build result: ABORTEDGitHub 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. 💣 |
|
@owncloud-bot retest this please |
|
🚀 Test PASSed. 🚀 |
|
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? |
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. |
|
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. |
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. |
|
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. |
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
good catch... fixed in one second 😉
ff26037 to
c8a1929
Compare
|
🚀 Test PASSed. 🚀 |
|
I guess this one is ready to be merged now, right? |
|
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? |
|
Having reviewed the code (but not tested) I say it is OK. |
|
I'll test this. |
… for both the real file and the part file, because some information from the part file might be needed later
c8a1929 to
2af7256
Compare
|
rebased to resolve merge conflicts |
|
The inspection completed: 6 updated code elements |
|
👍 |
|
🚀 Test PASSed. 🚀 |
if we read a .part file we try to get the file info from the real file
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!