dustin10/VichUploaderBundle — Issue #15: unlink warning
Author: inmarelibero
Created: 2012-03-04 12:00:34+00:00
State: open

I have VichUploader installed with

vich_uploader:
db_driver: orm
mappings:
product_image:
upload_dir: [my_dir]
delete_on_remove: true [this is the point]

scenario:

- I upload a file attached to an entoty
- I remove the file from the filesystem manually (e.g. console)
- I remove the entity via symfony

at this point it gives me:

Warning: unlink([file_path]) [function.unlink]: No such file
or directory in
[my_site]/vendor/bundles/Vich/UploaderBundle/Storage/FileSystemStorage.php line 68

because it tries to unlink a non-existing file via

unlink(sprintf('%s/%s', $mapping->getUploadDir(), $name));

and gives correctly a warning.

I think this should be silent, if the file is not found it shouldn't raise any warning or error

maybe a try/catch would be a solution? instead of (file_exists && !is_dir)

try {
unlink(sprintf('%s/%s', $mapping->getUploadDir(), $name));
catch (\Exception $e) {}