Module: PDK::Util::Filesystem
- Defined in:
- lib/pdk/util/filesystem.rb
Class Method Summary collapse
- .cp(*args) ⇒ Object
-
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage.
- .exist?(*args) ⇒ Boolean
- .expand_path(*args) ⇒ Object
- .file?(*args) ⇒ Boolean
- .fnmatch(*args) ⇒ Object
- .fnmatch?(*args) ⇒ Boolean
- .glob(*args) ⇒ Object
- .mkdir_p(*args) ⇒ Object
- .mv(*args) ⇒ Object
- .read_file(file, nil_on_error: false, open_args: 'r') ⇒ Object
- .readable?(*args) ⇒ Boolean
- .remove_entry_secure(*args) ⇒ Object
- .rm(*args) ⇒ Object
- .rm_f(*args) ⇒ Object
- .rm_rf(*args) ⇒ Object
- .stat(*args) ⇒ Object
- .symlink?(*args) ⇒ Boolean
- .write_file(path, content) ⇒ Object
- .zero?(*args) ⇒ Boolean
Class Method Details
.cp(*args) ⇒ Object
112 113 114 |
# File 'lib/pdk/util/filesystem.rb', line 112 def cp(*args) FileUtils.cp(*args) end |
.directory?(*args) ⇒ Boolean
:nocov: These methods just wrap core Ruby functionality and can be ignored for code coverage
32 33 34 |
# File 'lib/pdk/util/filesystem.rb', line 32 def directory?(*args) File.directory?(*args) end |
.exist?(*args) ⇒ Boolean
72 73 74 |
# File 'lib/pdk/util/filesystem.rb', line 72 def exist?(*args) File.exist?(*args) end |
.expand_path(*args) ⇒ Object
47 48 49 |
# File 'lib/pdk/util/filesystem.rb', line 47 def (*args) File.(*args) end |
.file?(*args) ⇒ Boolean
42 43 44 |
# File 'lib/pdk/util/filesystem.rb', line 42 def file?(*args) File.file?(*args) end |
.fnmatch(*args) ⇒ Object
57 58 59 |
# File 'lib/pdk/util/filesystem.rb', line 57 def fnmatch(*args) File.fnmatch(*args) end |
.fnmatch?(*args) ⇒ Boolean
62 63 64 |
# File 'lib/pdk/util/filesystem.rb', line 62 def fnmatch?(*args) File.fnmatch?(*args) end |
.glob(*args) ⇒ Object
52 53 54 |
# File 'lib/pdk/util/filesystem.rb', line 52 def glob(*args) Dir.glob(*args) end |
.mkdir_p(*args) ⇒ Object
37 38 39 |
# File 'lib/pdk/util/filesystem.rb', line 37 def mkdir_p(*args) FileUtils.mkdir_p(*args) end |
.mv(*args) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/pdk/util/filesystem.rb', line 117 def mv(*args) FileUtils.mv(*args) 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 |
# 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 => e raise e unless nil_on_error nil end |
.readable?(*args) ⇒ Boolean
67 68 69 |
# File 'lib/pdk/util/filesystem.rb', line 67 def readable?(*args) File.readable?(*args) end |
.remove_entry_secure(*args) ⇒ Object
92 93 94 |
# File 'lib/pdk/util/filesystem.rb', line 92 def remove_entry_secure(*args) FileUtils.remove_entry_secure(*args) end |
.rm(*args) ⇒ Object
77 78 79 |
# File 'lib/pdk/util/filesystem.rb', line 77 def rm(*args) FileUtils.rm(*args) end |
.rm_f(*args) ⇒ Object
82 83 84 |
# File 'lib/pdk/util/filesystem.rb', line 82 def rm_f(*args) FileUtils.rm_f(*args) end |
.rm_rf(*args) ⇒ Object
87 88 89 |
# File 'lib/pdk/util/filesystem.rb', line 87 def rm_rf(*args) FileUtils.rm_rf(*args) end |
.stat(*args) ⇒ Object
102 103 104 |
# File 'lib/pdk/util/filesystem.rb', line 102 def stat(*args) File.stat(*args) end |
.symlink?(*args) ⇒ Boolean
107 108 109 |
# File 'lib/pdk/util/filesystem.rb', line 107 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.open(path, 'wb') { |f| f.write(content) } end |
.zero?(*args) ⇒ Boolean
97 98 99 |
# File 'lib/pdk/util/filesystem.rb', line 97 def zero?(*args) File.zero?(*args) end |