-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating an asset can cause stat issues #467
Comments
Actually forcing the hash is not a solution either since we have this silverstripe-assets/src/Flysystem/FlysystemAssetStore.php Lines 1265 to 1271 in 1890fcc
which would cause the file to be marked as "not found" even if it's there. So back to square one, i need to update the hash. Currently I have the following behaviour:
I'm not sure how we end up in a situation where truncating the directory tries to find the old asset but if i comment the truncateDir line, it works! The full trace is as follow SplFileInfo->getType() |
Actually the issue might be in flysystem itself, for reference |
Rewriting the truncateDirectory method like this "fixes" the issue. The directory won't be truncated if the deleted file was the only in there but it's better than having the whole thing crashing. /**
* Clear directory if it's empty
*
* @param string $dirname Name of directory
* @param Filesystem $filesystem
*/
protected function truncateDirectory($dirname, Filesystem $filesystem)
{
// Check valid dirname
if (!$dirname || !ltrim($dirname, '.')) {
return;
}
// We keep empty dir
if ($this->config()->get('keep_empty_dirs')) {
return;
}
// listContents can throw RuntimeExceptions due to stat cache
try {
$listContents = $filesystem->listContents($dirname);
if ($listContents) {
return;
}
} catch (RuntimeException $ex) {
// Ignore 'Uncaught RuntimeException: SplFileInfo::getType(): Lstat failed for' errors
return;
}
$filesystem->deleteDir($dirname);
$this->truncateDirectory(dirname($dirname), $filesystem);
} |
So, basically calling |
@emteknetnz not quite, the file is still there on the filesystem, but moved to a folder with the new hash. In fact, everything works fine if you don't truncate the directory, the hash is updated properly and silverstripe finds it back. the scenario is this:
I don't know if it's only on my local windows machine or also on a linux/mac server. |
if you want to replicate the issue, you can try with my module lekoala/silverstyripe-encrypt and comment the lines where i set keep_empty_dirs to true. Define a DataObject with a has_one File and run in onBeforeWrite if($this->FileID) { $this->File()->encryptFileIfNeeded(); } |
I have discovered a potential issue or at least something that is really not clear when working on one of my module
I'm trying to update the content from a file using the
setFromStream
method like thishttps://github.com/lekoala/silverstripe-encrypt/blob/22b305c1301d6f67fd3d57df1b04d7bee6308c82/src/EncryptedDBFile.php#L108
I see it's updating the filename based on the file results array... but since the content has been updated, the hash is updated as well. Which means the file is moved to a new folder. All that is fine, except that the FileHash field in my File table is not updated and it seems that the file could not be found again after being updated (it's there on the filesystem in the new hash folder, but it's shown as not found by the uploader and trying to manipulate the file in php results in strange errors).
Did I miss something? I expect the setFromStream method to update the hash as well if necessary. I've tried setting the hash manually (something like $file->FileHash = $newHash) but it doesn't seem to get saved.
Currently my solution is to pass along the previous hash to the setFromStream method (which also prevent moving the file around for no reason).
EDIT: i've changed the title of the issue, please read below
The text was updated successfully, but these errors were encountered: