Ticket #4360 defect new

Opened 3 years ago

Last modified 8 months ago

filepath.FilePath.setContent doesn't preserve permissions

Reported by: therve Owned by:
Priority: high Milestone:
Component: core Keywords:
Cc: richard@…, keturn@… Branch:
Author: Launchpad Bug:

Description

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

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

Change History

1

Changed 2 years ago by <automation>

  • owner glyph deleted

2

Changed 2 years ago by rwall

  • cc richard@… added
  • summary changed from FilePath.setContent doesn't preserve permissions to filepath.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 os.open, 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)
'0100755'
>>> f.chmod(0400)
>>> f.restat()
>>> oct(f.statinfo.st_mode)
'0100400'
>>> f.setContent('foo')
>>> f.restat()
>>> oct(f.statinfo.st_mode)
'0100755'

Changed 2 years ago by rwall

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

3

Changed 11 months ago by acapnotic

  • cc keturn@… added

4

Changed 8 months ago by exarkun

  • priority changed from normal to high

5

Changed 8 months ago by lewq

+1 for also retaining owner and group info.

Note: See TracTickets for help on using tickets.