File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -691,6 +691,9 @@ def flush(self):
691691 _sync_close (new_file )
692692 # self._file is about to get replaced, so no need to sync.
693693 self ._file .close ()
694+ # Make sure the new file's mode is the same as the old file's
695+ mode = os .stat (self ._path ).st_mode
696+ os .chmod (new_file .name , mode )
694697 try :
695698 os .rename (new_file .name , self ._path )
696699 except OSError as e :
Original file line number Diff line number Diff line change @@ -969,6 +969,23 @@ def test_add_doesnt_rewrite(self):
969969 self ._box = self ._factory (self ._path )
970970 self .assertEqual (len (self ._box ), 1 )
971971
972+ def test_permissions_after_flush (self ):
973+ # See issue #5346
974+
975+ # Make the mailbox world writable. It's unlikely that the new
976+ # mailbox file would have these permissions after flush(),
977+ # because umask usually prevents it.
978+ mode = os .stat (self ._path ).st_mode | 0o666
979+ os .chmod (self ._path , mode )
980+
981+ self ._box .add (self ._template % 0 )
982+ i = self ._box .add (self ._template % 1 )
983+ # Need to remove one message to make flush() create a new file
984+ self ._box .remove (i )
985+ self ._box .flush ()
986+
987+ self .assertEqual (os .stat (self ._path ).st_mode , mode )
988+
972989
973990class _TestMboxMMDF (_TestSingleFile ):
974991
Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ Core and Builtins
1414Library
1515-------
1616
17+ - Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox
18+ files on flush().
19+
1720- Issue #10571: Fix the "--sign" option of distutils' upload command.
1821 Patch by Jakub Wilk.
1922
You can’t perform that action at this time.
0 commit comments