Module: ConfCtl::Utils::File
- Included in:
- GCRoot, Generation::BuildList, Nix, Swpins::Core
- Defined in:
- lib/confctl/utils/file.rb
Instance Method Summary collapse
-
#replace_symlink(path, dst) ⇒ Object
Atomically replace or create symlink.
-
#unlink_if_exists(path) ⇒ Object
Unlink file if it exists.
Instance Method Details
#replace_symlink(path, dst) ⇒ Object
Atomically replace or create symlink
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_if_exists(path) ⇒ Object
Unlink file if it exists
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 |