Module: PDK::Util::Filesystem
- Defined in:
- lib/pdk/util/filesystem.rb
Class Method Summary collapse
- .cp(*args, **kwargs) ⇒ Object
-
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage.
- .executable?(*args) ⇒ Boolean
- .exist?(*args) ⇒ Boolean
- .expand_path(*args) ⇒ Object
- .file?(*args) ⇒ Boolean
- .fnmatch(*args) ⇒ Object
- .fnmatch?(*args) ⇒ Boolean
- .glob(*args) ⇒ Object
- .make_executable(file) ⇒ Object
- .mkdir_p(*args, **kwargs) ⇒ Object
- .mv(*args, **kwargs) ⇒ Object
- .read_file(file, nil_on_error: false, open_args: 'r') ⇒ Object
- .readable?(*args) ⇒ Boolean
- .remove_entry_secure(*args) ⇒ Object
- .rm(*args, **kwargs) ⇒ Object
- .rm_f(*args, **kwargs) ⇒ Object
- .rm_rf(*args, **kwargs) ⇒ Object
- .stat(*args) ⇒ Object
- .symlink?(*args) ⇒ Boolean
- .write_file(path, content) ⇒ Object
- .zero?(*args) ⇒ Boolean
Class Method Details
.cp(*args, **kwargs) ⇒ Object
118 119 120 |
# File 'lib/pdk/util/filesystem.rb', line 118 def cp(*args, **kwargs) FileUtils.cp(*args, **kwargs) end |
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage
38 39 40 |
# File 'lib/pdk/util/filesystem.rb', line 38 def directory?(*args) File.directory?(*args) end |
.executable?(*args) ⇒ Boolean
142 143 144 |
# File 'lib/pdk/util/filesystem.rb', line 142 def executable?(*args) File.executable?(*args) end |
.exist?(*args) ⇒ Boolean
78 79 80 |
# File 'lib/pdk/util/filesystem.rb', line 78 def exist?(*args) File.exist?(*args) end |
.expand_path(*args) ⇒ Object
53 54 55 |
# File 'lib/pdk/util/filesystem.rb', line 53 def (*args) File.(*args) end |
.file?(*args) ⇒ Boolean
48 49 50 |
# File 'lib/pdk/util/filesystem.rb', line 48 def file?(*args) File.file?(*args) end |
.fnmatch(*args) ⇒ Object
63 64 65 |
# File 'lib/pdk/util/filesystem.rb', line 63 def fnmatch(*args) File.fnmatch(*args) end |
.fnmatch?(*args) ⇒ Boolean
68 69 70 |
# File 'lib/pdk/util/filesystem.rb', line 68 def fnmatch?(*args) File.fnmatch?(*args) end |
.glob(*args) ⇒ Object
58 59 60 |
# File 'lib/pdk/util/filesystem.rb', line 58 def glob(*args) Dir.glob(*args) end |
.make_executable(file) ⇒ Object
30 31 32 |
# File 'lib/pdk/util/filesystem.rb', line 30 def make_executable(file) FileUtils.chmod('a+x', file) end |
.mkdir_p(*args, **kwargs) ⇒ Object
43 44 45 |
# File 'lib/pdk/util/filesystem.rb', line 43 def mkdir_p(*args, **kwargs) FileUtils.mkdir_p(*args, **kwargs) end |
.mv(*args, **kwargs) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pdk/util/filesystem.rb', line 123 def mv(*args, **kwargs) FileUtils.mv(*args, **kwargs) rescue Errno::ENOENT # PDK-1169 - FileUtils.mv raises Errno::ENOENT when moving files inside # VMWare shared folders on Windows. So we need to catch this # case, check if the file exists to see if the exception is # legit and "move" the file with cp & rm. src, dest, opts = args raise unless File.exist?(src) FileUtils.cp(src, dest, preserve: true) if (opts ||= {})[:secure] FileUtils.remove_entry_secure(src, opts[:force]) else FileUtils.remove_entry(src, opts[:force]) end end |
.read_file(file, nil_on_error: false, open_args: 'r') ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/pdk/util/filesystem.rb', line 21 def read_file(file, nil_on_error: false, open_args: 'r') File.read(file, open_args: Array(open_args)) rescue StandardError => e raise e unless nil_on_error nil end |
.readable?(*args) ⇒ Boolean
73 74 75 |
# File 'lib/pdk/util/filesystem.rb', line 73 def readable?(*args) File.readable?(*args) end |
.remove_entry_secure(*args) ⇒ Object
98 99 100 |
# File 'lib/pdk/util/filesystem.rb', line 98 def remove_entry_secure(*args) FileUtils.remove_entry_secure(*args) end |
.rm(*args, **kwargs) ⇒ Object
83 84 85 |
# File 'lib/pdk/util/filesystem.rb', line 83 def rm(*args, **kwargs) FileUtils.rm(*args, **kwargs) end |
.rm_f(*args, **kwargs) ⇒ Object
88 89 90 |
# File 'lib/pdk/util/filesystem.rb', line 88 def rm_f(*args, **kwargs) FileUtils.rm_f(*args, **kwargs) end |
.rm_rf(*args, **kwargs) ⇒ Object
93 94 95 |
# File 'lib/pdk/util/filesystem.rb', line 93 def rm_rf(*args, **kwargs) FileUtils.rm_rf(*args, **kwargs) end |
.stat(*args) ⇒ Object
108 109 110 |
# File 'lib/pdk/util/filesystem.rb', line 108 def stat(*args) File.stat(*args) end |
.symlink?(*args) ⇒ Boolean
113 114 115 |
# File 'lib/pdk/util/filesystem.rb', line 113 def symlink?(*args) File.symlink?(*args) end |
.write_file(path, content) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pdk/util/filesystem.rb', line 7 def write_file(path, content) raise ArgumentError, 'content must be a String' unless content.is_a?(String) raise ArgumentError, 'path must be a String or Pathname' unless path.is_a?(String) || path.respond_to?(:to_path) # Harmonize newlines across platforms. content = content.encode(universal_newline: true) # Make sure all written files have a trailing newline. content += "\n" unless content[-1] == "\n" File.binwrite(path, content) end |
.zero?(*args) ⇒ Boolean
103 104 105 |
# File 'lib/pdk/util/filesystem.rb', line 103 def zero?(*args) File.empty?(*args) end |