Class: Puppet::FileSystem::Windows
- Defined in:
- lib/puppet/file_system/windows.rb
Instance Method Summary collapse
- #chmod(mode, path) ⇒ Object
- #exist?(path) ⇒ Boolean
- #expand_path(path, dir_string = nil) ⇒ Object
- #lstat(path) ⇒ Object
- #read_preserve_line_endings(path) ⇒ Object
- #readlink(path) ⇒ Object
- #stat(path) ⇒ Object
- #symlink(path, dest, options = {}) ⇒ Object
- #symlink?(path) ⇒ Boolean
- #unlink(*file_names) ⇒ Object
Methods inherited from Posix
Methods inherited from FileImpl
#assert_path, #basename, #binread, #children, #compare_stream, #dir, #directory?, #each_line, #exclusive_create, #exclusive_open, #executable?, #file?, #mkpath, #open, #path_string, #pathname, #read, #size, #touch, #writable?
Instance Method Details
#chmod(mode, path) ⇒ Object
97 98 99 |
# File 'lib/puppet/file_system/windows.rb', line 97 def chmod(mode, path) Puppet::Util::Windows::Security.set_mode(mode, path.to_s) end |
#exist?(path) ⇒ Boolean
25 26 27 |
# File 'lib/puppet/file_system/windows.rb', line 25 def exist?(path) return Puppet::Util::Windows::File.exist?(path) end |
#expand_path(path, dir_string = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet/file_system/windows.rb', line 6 def (path, dir_string = nil) # ensure `nil` values behave like underlying File.expand_path string_path = ::File.(path.nil? ? nil : path_string(path), dir_string) # if no tildes, nothing to expand, no need to call Windows API, return original string return string_path if !string_path.index('~') begin # no need to do existence check up front as GetLongPathName implies that check is performed # and it should be the exception that files aren't actually present string_path = Puppet::Util::Windows::File.get_long_pathname(string_path) rescue Puppet::Util::Windows::Error => e # preserve original File.expand_path behavior for file / path not found by returning string raise if (e.code != Puppet::Util::Windows::File::ERROR_FILE_NOT_FOUND && e.code != Puppet::Util::Windows::File::ERROR_PATH_NOT_FOUND) end string_path end |
#lstat(path) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/puppet/file_system/windows.rb', line 90 def lstat(path) if ! Puppet.features.manages_symlinks? return Puppet::Util::Windows::File.stat(path) end Puppet::Util::Windows::File.lstat(path) end |
#read_preserve_line_endings(path) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/puppet/file_system/windows.rb', line 101 def read_preserve_line_endings(path) contents = path.read( :mode => 'rb', :encoding => Encoding::UTF_8) contents = path.read( :mode => 'rb', :encoding => Encoding::default_external) unless contents.valid_encoding? contents = path.read unless contents.valid_encoding? contents end |
#readlink(path) ⇒ Object
55 56 57 58 |
# File 'lib/puppet/file_system/windows.rb', line 55 def readlink(path) raise_if_symlinks_unsupported Puppet::Util::Windows::File.readlink(path) end |
#stat(path) ⇒ Object
86 87 88 |
# File 'lib/puppet/file_system/windows.rb', line 86 def stat(path) Puppet::Util::Windows::File.stat(path) end |
#symlink(path, dest, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/file_system/windows.rb', line 29 def symlink(path, dest, = {}) raise_if_symlinks_unsupported dest_exists = exist?(dest) # returns false on dangling symlink dest_stat = Puppet::Util::Windows::File.stat(dest) if dest_exists # silent fail to preserve semantics of original FileUtils return 0 if dest_exists && dest_stat.ftype == 'directory' if dest_exists && dest_stat.ftype == 'file' && [:force] != true raise(Errno::EEXIST, "#{dest} already exists and the :force option was not specified") end if [:noop] != true ::File.delete(dest) if dest_exists # can only be file Puppet::Util::Windows::File.symlink(path, dest) end 0 end |
#symlink?(path) ⇒ Boolean
50 51 52 53 |
# File 'lib/puppet/file_system/windows.rb', line 50 def symlink?(path) return false if ! Puppet.features.manages_symlinks? Puppet::Util::Windows::File.symlink?(path) end |
#unlink(*file_names) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puppet/file_system/windows.rb', line 60 def unlink(*file_names) if ! Puppet.features.manages_symlinks? return ::File.unlink(*file_names) end file_names.each do |file_name| file_name = file_name.to_s # handle PathName stat = Puppet::Util::Windows::File.stat(file_name) rescue nil # sigh, Ruby + Windows :( if !stat ::File.unlink(file_name) rescue Dir.rmdir(file_name) elsif stat.ftype == 'directory' if Puppet::Util::Windows::File.symlink?(file_name) Dir.rmdir(file_name) else raise Errno::EPERM.new(file_name) end else ::File.unlink(file_name) end end file_names.length end |