In perl.git, the branch tonyc/127663-safe-inplace has been created

<http://perl5.git.perl.org/perl.git/commitdiff/63c04f9a3957427689ac7169e8fc5fbc745c2b4b?hp=0000000000000000000000000000000000000000>

        at  63c04f9a3957427689ac7169e8fc5fbc745c2b4b (commit)

- Log -----------------------------------------------------------------
commit 63c04f9a3957427689ac7169e8fc5fbc745c2b4b
Author: Tony Cook <[email protected]>
Date:   Mon May 9 14:59:56 2016 +1000

    (perl #127663) WIP, safer in-place editing
    
    Previously in-place editing opened the file then immediately
    *replaced* the file, so if an error occurs while writing the output,
    such as running out of space, the content of the original file is lost.
    
    This changes in-place editing to write to a work file which is renamed
    over the original only once the output file is successfully closed.
    
    It may also fix an issue with setting uid/gid file modes for recursive
    in-place editing.
    
    The implementation (beyond some TODO issues below) has at least one
    problem - if the user code changes directory between the file open and
    the close then the final clean-up stage is going to fail if the input
    name wasn't an absolute path.
    
    This might be fixable, but on some systems it may put the perl process
    in a difficult to recover from position - if the system doesn't
    implement getcwd() perl may change directory out of the original and not
    have a way to return to it.
    
    Now the TODO issues:
    
    - the code uses mkstemp() - solvable by adapting a BSD implementation if
    the system doesn't provide it.
    
    - the code uses rename() - I need to re-work the code to use link() /
    UNLINK() where rename() isn't available
    
    - perl -i.back -pe 'exit' foo # leaves an orphan work file, this might
    be messy to fix (the fix would be trashing the work file, not moving it
    over the original).
    
    - where rename() and link() are available it might be desirable to link
    the backup file to the original file then rename the temp over the
    original so there's no point where the original doesn't exist.  This
    would need to fallback to rename/rename just in case the system supports
    link but the current filesystem doesn't.
    
    - tests - existing tests caught one problem, but it needs more.
-----------------------------------------------------------------------

--
Perl5 Master Repository

Reply via email to