phpapacheubuntupermissionswpmu

PHP 5.5 rename() modifes files and removes permissions - why?


I'm using the WP Smushit Pro plugin created by WPMU DEV. Their support won't go this far so I'm reaching out. I'm pretty sure it's my server that has the issue anyway.

When an Image is Smushed, the PHP function rename() runs and overwrites the original image.

Problem is:

Permissions are changed leaving the image inaccessible to online users

Previous permissions: rw-r--r-- (0644)
After modifed Perms : rw------- (0600)


UPDATE

The optimized (smushed) image is created as a .tmp file (rename()) in the same directory before being copy()'d to overwrite the existing file.

Image Optimization Workflow

  1. Send original image (imagename) to get smushed
  2. Image returns, store it as imagename.tmp file
  3. copy imagename.tmp file to imagename - the original file

Have you encountered this type of permissions modification before?
If so, what can be done to gracefully solve the problem?


Solution

  • Please be aware of what it means to rename a file.

    When the file remains on the same file system, a rename is not actually an operation on the file itself. It only modifies directories: the directory the file was in and the directory the file will be in. It does not affect the content or properties of the file itself, such as its access permissions and ownership. (A file's name is not a property of the file, but of a directory entry pointing to the file.)

    For consistency, this also applies when a file is moved across file systems, even though in that case, underneath the covers, a new file must be made and its contents and properties most be copied over.

    So you probably need to fix the default permissions used to create new files (the umask) that is in effect for the plugin.