os

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 4 Imported by: 7

Documentation

Overview

The os package implements replacement functions for the Go [os/https://pkg.go.dev/os] package.

It currently implements:

  • 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)
  • IsDevNull function to check if a filepath corresponds to the system /dev/null device

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDevNull added in v0.8.7

func IsDevNull(path string) bool

Returns true if the filepath corresponds to: - /dev/null (Linux) - /dev/null (MacOS) - nul (Windows)

func Rename

func Rename(oldpath, newpath string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL