Class: DRbFileClientReadWrite

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

Instance Method Summary collapse

Constructor Details

#initializeDRbFileClientReadWrite

Returns a new instance of DRbFileClientReadWrite.



11
12
13
14
# File 'lib/drb_fileclient-readwrite.rb', line 11

def initialize()
  @@directory ||= nil
  @@file ||= nil
end

Instance Method Details

#chdir(raw_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/drb_fileclient-readwrite.rb', line 16

def chdir(raw_path)
  puts 'inside 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
    puts '@@directory:' + @@directory.inspect
  else
    'No such file or directory'
  end

end

#directory?(filename = @@filename) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/drb_fileclient-readwrite.rb', line 38

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



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/drb_fileclient-readwrite.rb', line 53

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



65
66
67
68
69
70
71
# File 'lib/drb_fileclient-readwrite.rb', line 65

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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/drb_fileclient-readwrite.rb', line 73

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

#pwdObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/drb_fileclient-readwrite.rb', line 88

def pwd()

  puts 'inside pwd'
  puts '@@directory: ' + @@directory.inspect
  puts '@@file: ' + @@file.inspect

  return Dir.pwd unless @@directory

  '/' + @@directory if @@file

end

#rm(path) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/drb_fileclient-readwrite.rb', line 100

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



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

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



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/drb_fileclient-readwrite.rb', line 130

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



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/drb_fileclient-readwrite.rb', line 146

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