Class: DRbFileClientReadWrite

Inherits:
DRbFileClientReader
  • Object
show all
Defined in:
lib/drb_fileclient-readwrite.rb

Instance Method Summary collapse

Instance Method Details

#chdir(raw_path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/drb_fileclient-readwrite.rb', line 11

def chdir(raw_path)

  return Dir.chdir raw_path unless @directory or raw_path =~ /^dfs:\/\//

  if raw_path[0] == '/'  then
    directory = raw_path[1..-1]
  elsif raw_path =~ /^dfs:\/\//
    @file, directory = parse_path(raw_path)
  else
    directory = File.join(@directory, raw_path)
  end

  if @file.exists? directory then
    @directory = directory
  else
    'No such file or directory'
  end

end

#directory?(filename = @filename) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/drb_fileclient-readwrite.rb', line 31

def directory?(filename=@filename)

  return File.directory? filename unless @directory or filename =~ /^dfs:\/\//

  if filename =~ /^dfs:\/\// then
    @file, filename2 = parse_path(filename)
  else

    filename2 = File.join(@directory, filename)
  end

  @file.directory?(filename2)

end

#glob(s) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/drb_fileclient-readwrite.rb', line 46

def glob(s)

  if s =~ /^dfs:\/\// then
    @file, s2 = parse_path(s)
  else
    s2 = File.join(@directory, s)
  end

  @file.glob s2

end

#mkdir(name) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/drb_fileclient-readwrite.rb', line 58

def mkdir(name)

  return FileUtils.mkdir name unless @directory or name =~ /^dfs:\/\//

  @file, path = parse_path(name)
  @file.mkdir path
end

#mkdir_p(raw_path) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/drb_fileclient-readwrite.rb', line 66

def mkdir_p(raw_path)

  unless @directory or raw_path =~ /^dfs:\/\// then
    return FileUtils.mkdir_p raw_path
  end

  if raw_path =~ /^dfs:\/\// then
    @file, filepath = parse_path(raw_path)
  else
    filepath = File.join(@directory, raw_path)
  end

  @file.mkdir_p filepath
end

#rm(path) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/drb_fileclient-readwrite.rb', line 81

def rm(path)

  return FileUtils.rm path unless @directory or path =~ /^dfs:\/\//

  if path =~ /^dfs:\/\// then
    @file, path2 = parse_path( path)
  else
    path2 = File.join(@directory, path)
  end

  @file.rm  path2

end

#rm_r(path, force: false) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/drb_fileclient-readwrite.rb', line 95

def rm_r(path, force: false)

  unless @directory or path =~ /^dfs:\/\// then
    return FileUtils.rm_r(path, force: force)
  end

  if path =~ /^dfs:\/\// then
    @file, path2 = parse_path( path)
  else
    path2 = File.join(@directory, path)
  end

  @file.rm_r(path2, force: force)

end

#touch(s, mtime: Time.now) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/drb_fileclient-readwrite.rb', line 111

def touch(s, mtime: Time.now)

  unless @directory or s =~ /^dfs:\/\// then
    return FileUtils.touch(s, mtime: mtime)
  end

  if s =~ /^dfs:\/\// then
    @file, s2 = parse_path(s)
  else
    s2 = File.join(@directory, s)
  end

  @file.touch s2, mtime: mtime

end

#write(filename = @filename, s) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/drb_fileclient-readwrite.rb', line 127

def write(filename=@filename, s)

  return File.write filename, s unless @directory or filename =~ /^dfs:\/\//

  if filename =~ /^dfs:\/\// then
    @file, path = parse_path(filename)
  else
    path = File.join(@directory, filename)
  end

  @file.write path, s

end