Exception: RIO::Exception::Copy

Inherits:
Base show all
Defined in:
lib/rio/exception/copy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, d, rerror) ⇒ Copy

Returns a new instance of Copy.



44
45
46
47
48
# File 'lib/rio/exception/copy.rb', line 44

def initialize(s,d,rerror)
  @src = ::RIO::Rio.new(s)
  @dst = ::RIO::Rio.new(d)
  @syserr = rerror
end

Instance Attribute Details

#dstObject (readonly)

Returns the value of attribute dst.



43
44
45
# File 'lib/rio/exception/copy.rb', line 43

def dst
  @dst
end

#srcObject (readonly)

Returns the value of attribute src.



42
43
44
# File 'lib/rio/exception/copy.rb', line 42

def src
  @src
end

#syserrObject (readonly)

Returns the value of attribute syserr.



41
42
43
# File 'lib/rio/exception/copy.rb', line 41

def syserr
  @syserr
end

Instance Method Details

#dir_info(f) ⇒ Object



65
66
67
68
# File 'lib/rio/exception/copy.rb', line 65

def dir_info(f)
  return unless f.dir?
  return "is a directory"
end

#explainObject



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rio/exception/copy.rb', line 82

def explain()
  s = "#{self.class}: failed copying '#{@src}' => #{@dst}"
  s += submsg("Err: #{@syserr}") if @syserr
  s += submsg("Src: '#{@src}' " + finfo(@src))
  s += submsg("Dst: '#{@dst}' " + finfo(@dst))
  target = ::RIO::rio(@dst,@src.filename) if @dst.dir?
  p target
  if target.exist?
    s += submsg("Tgt: '#{target} " + finfo(target))
  end
                        
  s += "\n"
end

#file_info(f) ⇒ Object



52
53
54
55
# File 'lib/rio/exception/copy.rb', line 52

def file_info(f)
  return unless f.file?
  "is a file"
end

#finfo(f) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rio/exception/copy.rb', line 69

def finfo(f)
  case 
  when (not f.exist?)
    return "does not exist"
  when f.symlink?
    return symlink_info(f)
  when f.dir?
    return dir_info(f)
  when f.file?
    return file_info(f)
  end
  return ""
end

#submsg(s) ⇒ Object



49
50
51
# File 'lib/rio/exception/copy.rb', line 49

def submsg(s)
  "\n\t" + s
end


56
57
58
59
60
61
62
63
64
# File 'lib/rio/exception/copy.rb', line 56

def symlink_info(f)
  return unless f.symlink?
  t = f.readlink
  s = "is a symlink refering to #{t}"
  f.dirname.chdir {
    s += submsg("   : '#{t}' " + finfo(t))
  }
  return s
end