Class: NFS::FileProxy
- Inherits:
-
File
- Object
- File
- NFS::FileProxy
- Defined in:
- lib/nfs/file_proxy.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_lookup(name) ⇒ Object
- #_nfs_setup ⇒ Object
- #create(name, mode, uid, gid) ⇒ Object
- #delete(name) ⇒ Object
- #entries ⇒ Object
- #link(dir, name) ⇒ Object
- #lookup(name) ⇒ Object
- #mkdir(name, mode, uid, gid) ⇒ Object
- #readlink ⇒ Object
- #rename(from_name, to_dir, to_name) ⇒ Object
- #rmdir(name) ⇒ Object
- #symlink(name, to_name) ⇒ Object
- #unlink(name) ⇒ Object
- #utime(atime, mtime) ⇒ Object
Class Method Details
.new(*args, &block) ⇒ Object
4 5 6 |
# File 'lib/nfs/file_proxy.rb', line 4 def new(*args, &block) super(*args, &block)._nfs_setup end |
.open(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nfs/file_proxy.rb', line 8 def open(*args) f = super(*args)._nfs_setup if block_given? begin return yield(f) ensure f.close end end f end |
Instance Method Details
#_lookup(name) ⇒ Object
45 46 47 |
# File 'lib/nfs/file_proxy.rb', line 45 def _lookup(name) File.(name, @absolute_path) end |
#_nfs_setup ⇒ Object
23 24 25 26 27 |
# File 'lib/nfs/file_proxy.rb', line 23 def _nfs_setup @absolute_path = File.(path) @looked_up = {} self end |
#create(name, mode, uid, gid) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nfs/file_proxy.rb', line 29 def create(name, mode, uid, gid) f = nil begin f = self.class.new(_lookup(name), File::RDWR | File::CREAT, mode) rescue f = self.class.new(_lookup(name), File::RDONLY | File::CREAT, mode) end stat = f.lstat @looked_up[[stat.ino, name]] = f [f, stat] end |
#delete(name) ⇒ Object
68 69 70 |
# File 'lib/nfs/file_proxy.rb', line 68 def delete(name) File.delete(_lookup(name)) end |
#entries ⇒ Object
109 110 111 |
# File 'lib/nfs/file_proxy.rb', line 109 def entries Dir.entries(@absolute_path) end |
#link(dir, name) ⇒ Object
76 77 78 |
# File 'lib/nfs/file_proxy.rb', line 76 def link(dir, name) File.link(@absolute_path, dir._lookup(name)) end |
#lookup(name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nfs/file_proxy.rb', line 49 def lookup(name) f = nil begin f = self.class.new(_lookup(name), File::RDWR) rescue f = self.class.new(_lookup(name), File::RDONLY) end stat = f.lstat key = [stat.ino, name] if @looked_up.include?(key) @looked_up[key] else @looked_up[key] = f end end |
#mkdir(name, mode, uid, gid) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/nfs/file_proxy.rb', line 88 def mkdir(name, mode, uid, gid) path = _lookup(name) Dir.mkdir(path, mode) f = self.class.new(path) #f.chown(uid, gid) stat = f.lstat @looked_up[[stat.ino, name]] = f [f, stat] end |
#readlink ⇒ Object
84 85 86 |
# File 'lib/nfs/file_proxy.rb', line 84 def readlink File.readlink(@absolute_path) end |
#rename(from_name, to_dir, to_name) ⇒ Object
72 73 74 |
# File 'lib/nfs/file_proxy.rb', line 72 def rename(from_name, to_dir, to_name) File.rename(_lookup(from_name), to_dir._lookup(to_name)) end |
#rmdir(name) ⇒ Object
101 102 103 |
# File 'lib/nfs/file_proxy.rb', line 101 def rmdir(name) Dir.delete(_lookup(name)) end |
#symlink(name, to_name) ⇒ Object
80 81 82 |
# File 'lib/nfs/file_proxy.rb', line 80 def symlink(name, to_name) File.symlink(to_name, _lookup(name)) end |
#unlink(name) ⇒ Object
105 106 107 |
# File 'lib/nfs/file_proxy.rb', line 105 def unlink(name) File.unlink(_lookup(name)) end |
#utime(atime, mtime) ⇒ Object
113 114 115 |
# File 'lib/nfs/file_proxy.rb', line 113 def utime(atime, mtime) File.utime(atime, mtime, @absolute_path) end |