Documentation
¶
Overview ¶
The os package implements replacement functions for the Go [os/https://pkg.go.dev/os] package.
It currently only implemants a replacement function for os.Rename to workaround the 'invalid cross-device link' error when renaming across file-systems
(cf. https://github.com/uhppoted/uhppoted-httpd/issues/20)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Rename ¶
Replacement implementation for os.Rename that copies the file if os.Rename fails with an error.
Use os.Rename to 'move' a file between filesystems on different filesystems fails with an 'invalid cross-device link' error. The replacement implementation first attempts a 'rename' and if that fails, creates a temporary file adjacent to the destination file, copies the source to the temporary file and then does an os.Rename(...) on the temporary file to overwrite the destination file.
The temporary file and original file are deleted.
NB: this is very much an application specific implementation - errors deleting the
temporary or original file are discarded on the basis that this operation is typically used to copy create an updated 'working file' from a temporary file and the application can and will use the updated working file even if the original file is not deleted.
NB: this implementation can potentially leave a temp file adjacent to the destination
file if it is interrupted while doing the final rename step. Although probably a reasonably rare occurrence, long-running systems should make provision for cleaning up unwanted temporary files. To facilitate identifying files that need to be cleaned up, the function consistently creates files with a .tmp extension.
References: 1. https://github.com/uhppoted/uhppoted-httpd/issues/20 2. https://github.com/golang/go/issues/41487)
Types ¶
This section is empty.