Make a backup file: Difference between revisions

Some examples on this page assume that the original file already exists.
(→‎{{header|Ruby}}: File.readlink is wrong because the link might not be in the current directory. Use File.realpath instead.)
(Some examples on this page assume that the original file already exists.)
Line 5:
In this task you should create a backup file from an existing file and then write new text to the old file.
The following issues should be handled:
* avoid making a copy of the file but instead rename the original and then write a new file with the original filename.
* if a copy needs to be made, please explain why rename is not possible.
* keep in mind symlinks, and do not rename or copy the link but the target. (If there is a link <code>foo -> bar/baz</code>, then <code>bar/baz</code> should be renamed to <code>bar/baz.backup</code> and then the new text should be written to <code>bar/baz</code>.)
(if there is a link <code>foo -> bar/baz</code>, then <code>bar/baz</code> should be renamed to <code>bar/baz.backup</code> and then the new text should be written to <code>bar/baz</code>)
 
* it is assumed that you have permission to write in the target location, thus permission errors need not be handled.
* you may choose the backup filename per preference or given limitations. (itIt should somehow include the original filename however.)
* please try to avoid executing external commands, and especially avoid calling a shell script.
 
Some examples on this page assume that the original file already exists. They might fail if some user is trying to create a new file.
 
=={{header|Common Lisp}}==
Anonymous user