Class: MiqFsUtil
- Inherits:
-
Object
- Object
- MiqFsUtil
- Defined in:
- lib/fs/MiqFsUtil.rb
Instance Attribute Summary collapse
-
#fromFs ⇒ Object
Returns the value of attribute fromFs.
-
#toFs ⇒ Object
Returns the value of attribute toFs.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#copy(from, to, recursive = false) ⇒ Object
Copy files and directories from fromFs to the toFs.
- #dumpSpec(specFile) ⇒ Object
-
#initialize(fromFs, toFs, us = nil) ⇒ MiqFsUtil
constructor
A new instance of MiqFsUtil.
-
#loadUpdateSpec(path) ⇒ Object
Load the update spec from a file in the fromFs.
- #setUpdateSpec(us) ⇒ Object
- #update ⇒ Object
- #updateSpec=(us) ⇒ Object
Constructor Details
#initialize(fromFs, toFs, us = nil) ⇒ MiqFsUtil
Returns a new instance of MiqFsUtil.
10 11 12 13 14 15 16 |
# File 'lib/fs/MiqFsUtil.rb', line 10 def initialize(fromFs, toFs, us = nil) setUpdateSpec(us) @fromFs = fromFs @toFs = toFs @verbose = false end |
Instance Attribute Details
#fromFs ⇒ Object
Returns the value of attribute fromFs.
8 9 10 |
# File 'lib/fs/MiqFsUtil.rb', line 8 def fromFs @fromFs end |
#toFs ⇒ Object
Returns the value of attribute toFs.
8 9 10 |
# File 'lib/fs/MiqFsUtil.rb', line 8 def toFs @toFs end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/fs/MiqFsUtil.rb', line 8 def verbose @verbose end |
Instance Method Details
#copy(from, to, recursive = false) ⇒ Object
Copy files and directories from fromFs to the toFs.
FILE -> FILE FILE -> DIR DIR -> DIR (recursive = true)
57 58 59 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fs/MiqFsUtil.rb', line 57 def copy(from, to, recursive = false) allTargets = [] from = [from] unless from.kind_of?(Array) from.each { |t| allTargets.concat(dirGlob(t)) } raise "copy: no source files matched" if allTargets.length == 0 if allTargets.length > 1 || recursive raise "copy: destination directory does not exist" unless @toFs.fileExists?(to) raise "copy: destination must be a directory for multi-file copy" unless @toFs.fileDirectory?(to) end allTargets.each do |f| owd = @fromFs.pwd @fromFs.chdir(File.dirname(f)) f = File.basename(f) # # Copy plain files. # if @fromFs.fileFile?(f) if @toFs.fileDirectory?(to) tf = File.join(to, File.basename(f)) else tf = to end copySingle(f, tf) next end # # If the recursive flag is not set, skip directories. # next unless recursive # # Recursively copy directory sub-tree. # @fromFs.chdir(f) td = File.join(to, f) @toFs.dirMkdir(td) unless @toFs.fileExists?(td) @fromFs.findEach('.') do |ff| tf = File.join(td, ff) if @fromFs.fileDirectory?(ff) @toFs.dirMkdir(tf) elsif @fromFs.fileFile?(ff) copySingle(ff, tf) end end # findEach @fromFs.chdir(owd) end # allTargets.each end |
#dumpSpec(specFile) ⇒ Object
45 46 47 48 |
# File 'lib/fs/MiqFsUtil.rb', line 45 def dumpSpec(specFile) raise "MiqFsUpdate.dumpSpec: no current update spec" unless @csa YAML.dump(@csa, File.open(specFile, "w")) end |
#loadUpdateSpec(path) ⇒ Object
Load the update spec from a file in the fromFs.
36 37 38 |
# File 'lib/fs/MiqFsUtil.rb', line 36 def loadUpdateSpec(path) @fromFs.fileOpen(path) { |fo| @csa = YAML.load(fo.read) } end |
#setUpdateSpec(us) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fs/MiqFsUtil.rb', line 22 def setUpdateSpec(us) if us @csa = us @csa = YAML.load_file(us) if @csa.kind_of? String @csa = [@csa] if @csa.kind_of? Hash raise "Invalid collection spec" unless @csa.kind_of? Array else @csa = nil end end |
#update ⇒ Object
40 41 42 43 |
# File 'lib/fs/MiqFsUtil.rb', line 40 def update raise "MiqFsUpdate.update: no current update spec" unless @csa @csa.each { |cs| doUpdate(OpenStruct.new(cs)) } end |
#updateSpec=(us) ⇒ Object
18 19 20 |
# File 'lib/fs/MiqFsUtil.rb', line 18 def updateSpec=(us) setUpdateSpec(us) end |