Opened 8 years ago

Last modified 4 years ago

#4360 defect new

filepath.FilePath.setContent doesn't preserve permissions

Reported by: therve Owned by:
Priority: high Milestone:
Component: core Keywords:
Cc: Richard Wall, acapnotic Branch:


For example, if you set the content of an executable file, the executable bit is removed after calling setContent. It should probably try to keep the previous ones.

Attachments (1)

filepath-preserve-permissions-4360-1.patch (1.5 KB) - added by Richard Wall 7 years ago.
A first attempt - next I will attempt to preserve owner and group

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by <automation>

Owner: Glyph deleted

comment:2 Changed 7 years ago by Richard Wall

Cc: Richard Wall added
Summary: FilePath.setContent doesn't preserve permissionsfilepath.FilePath.setContent doesn't preserve permissions

I created duplicate ticket #4988 before exarkun pointed this one out to me. Adding my description here.

setContent creates, writes and then renames a temporary file over the top of the original file...but it doesn't apply permissions that were present on the original file.

Furthermore, the mode flags passed to, make the file executable.

This behaviour seems unexpected and is likely to confuse users of FilePath until they dig into the source code.

Seems like it should be fairly easy to read the mode from the original file and apply it to the new file.

>>> f = FilePath('foo')
>>> f.setContent('foo')
>>> f.restat()
>>> oct(f.statinfo.st_mode)
>>> f.chmod(0400)
>>> f.restat()
>>> oct(f.statinfo.st_mode)
>>> f.setContent('foo')
>>> f.restat()
>>> oct(f.statinfo.st_mode)

Changed 7 years ago by Richard Wall

A first attempt - next I will attempt to preserve owner and group

comment:3 Changed 6 years ago by acapnotic

Cc: acapnotic added

comment:4 Changed 5 years ago by Jean-Paul Calderone

Priority: normalhigh

comment:5 Changed 5 years ago by lewq

+1 for also retaining owner and group info.

comment:6 Changed 4 years ago by Tom Prince

It might be nice if setContent optionally allowed you to specify the mode (for when creating a new file, for example).

comment:7 Changed 4 years ago by Jean-Paul Calderone

Sounds like a tricky API.

Would the mode be ignored if setContent weren't creating a new file (can setContent even easily tell if it is creating a new file or not)? Or would it just be equivalent to using FilePath.chmod afterwards?

Note: See TracTickets for help on using tickets.