Class: NFS::FileProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/nfs/file_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileProxy

Returns a new instance of FileProxy.



7
8
9
10
11
# File 'lib/nfs/file_proxy.rb', line 7

def initialize(path)
  @path = path
  @absolute_path = File.expand_path(path)
  @looked_up = {}
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/nfs/file_proxy.rb', line 5

def path
  @path
end

Instance Method Details

#_lookup(name) ⇒ Object



29
30
31
# File 'lib/nfs/file_proxy.rb', line 29

def _lookup(name)
  File.expand_path(name, @absolute_path)
end

#chmod(new_mode) ⇒ Object



98
99
100
# File 'lib/nfs/file_proxy.rb', line 98

def chmod(new_mode)
  File.chmod(new_mode, @absolute_path)
end

#chown(uid, gid) ⇒ Object



102
103
104
# File 'lib/nfs/file_proxy.rb', line 102

def chown(uid, gid)
  File.chown(uid, gid, @absolute_path)
end

#create(name, mode, uid, gid) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nfs/file_proxy.rb', line 13

def create(name, mode, uid, gid)
  path = _lookup(name)
  f = self.class.new(path)

  unless File.exist?(path)
    FileUtils.touch(path)
  end

  f.chmod(mode)
  f.chown(uid, gid)

  stat = f.lstat
  @looked_up[[stat.ino, name]] = f
  [f, stat]
end

#delete(name) ⇒ Object



46
47
48
# File 'lib/nfs/file_proxy.rb', line 46

def delete(name)
  File.delete(_lookup(name))
end

#entriesObject



82
83
84
# File 'lib/nfs/file_proxy.rb', line 82

def entries
  Dir.entries(@absolute_path)
end


54
55
56
# File 'lib/nfs/file_proxy.rb', line 54

def link(dir, name)
  File.link(@absolute_path, dir._lookup(name))
end

#lookup(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nfs/file_proxy.rb', line 33

def lookup(name)
  f = self.class.new(_lookup(name))

  stat = f.lstat
  key = [stat.ino, name]

  if @looked_up.include?(key)
    @looked_up[key]
  else
    @looked_up[key] = f
  end
end

#lstatObject



90
91
92
# File 'lib/nfs/file_proxy.rb', line 90

def lstat
  File.lstat(@absolute_path)
end

#mkdir(name, mode) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nfs/file_proxy.rb', line 62

def mkdir(name, mode)
  path = _lookup(name)
  Dir.mkdir(path, mode)

  f = self.class.new(path)

  stat = f.lstat
  @looked_up[[stat.ino, name]] = f

  [f, stat]
end

#rename(from_name, to_dir, to_name) ⇒ Object



50
51
52
# File 'lib/nfs/file_proxy.rb', line 50

def rename(from_name, to_dir, to_name)
  File.rename(_lookup(from_name), to_dir._lookup(to_name))
end

#rmdir(name) ⇒ Object



74
75
76
# File 'lib/nfs/file_proxy.rb', line 74

def rmdir(name)
  Dir.delete(_lookup(name))
end


58
59
60
# File 'lib/nfs/file_proxy.rb', line 58

def symlink(name, to_name)
  File.symlink(to_name, _lookup(name))
end

#truncate(len) ⇒ Object



94
95
96
# File 'lib/nfs/file_proxy.rb', line 94

def truncate(len)
  File.truncate(@absolute_path, len)
end


78
79
80
# File 'lib/nfs/file_proxy.rb', line 78

def unlink(name)
  File.unlink(_lookup(name))
end

#utime(atime, mtime) ⇒ Object



86
87
88
# File 'lib/nfs/file_proxy.rb', line 86

def utime(atime, mtime)
  File.utime(atime, mtime, @absolute_path)
end