Module: ConfCtl::Utils::File

Included in:
GCRoot, Generation::BuildList, Nix, Swpins::Core
Defined in:
lib/confctl/utils/file.rb

Instance Method Summary collapse

Instance Method Details

Atomically replace or create symlink

Parameters:

  • path (String)

    symlink path

  • dst (String)

    destination



6
7
8
9
10
# File 'lib/confctl/utils/file.rb', line 6

def replace_symlink(path, dst)
  replacement = "#{path}.new-#{SecureRandom.hex(3)}"
  File.symlink(dst, replacement)
  File.rename(replacement, path)
end

Unlink file if it exists

Parameters:

  • path (String)


14
15
16
17
18
19
# File 'lib/confctl/utils/file.rb', line 14

def unlink_if_exists(path)
  File.unlink(path)
  true
rescue Errno::ENOENT
  false
end