# File lib/fakefs/file.rb, line 130 def self.basename(*args) RealFile.basename(*args) end
# File lib/fakefs/file.rb, line 96 def self.const_missing(name) RealFile.const_get(name) end
# File lib/fakefs/file.rb, line 64 def self.ctime(path) if exists?(path) FileSystem.find(path).ctime else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 193 def self.delete(file_name, *additional_file_names) if !exists?(file_name) raise Errno::ENOENT, "No such file or directory - #{file_name}" end FileUtils.rm(file_name) additional_file_names.each do |file_name| FileUtils.rm(file_name) end additional_file_names.size + 1 end
# File lib/fakefs/file.rb, line 100 def self.directory?(path) if path.respond_to? :entry path.entry.is_a? FakeDir else result = FileSystem.find(path) result ? result.entry.is_a?(FakeDir) : false end end
# File lib/fakefs/file.rb, line 134 def self.dirname(path) RealFile.dirname(path) end
# File lib/fakefs/file.rb, line 39 def self.exist?(path) if(File.symlink?(path)) then referent = File.expand_path(File.readlink(path), File.dirname(path)) exist?(referent) else !!FileSystem.find(path) end end
# File lib/fakefs/file.rb, line 126 def self.expand_path(*args) RealFile.expand_path(*args) end
# File lib/fakefs/file.rb, line 31 def self.extname(path) RealFile.extname(path) end
# File lib/fakefs/file.rb, line 117 def self.file?(path) if path.respond_to? :entry path.entry.is_a? FakeFile else result = FileSystem.find(path) result ? result.entry.is_a?(FakeFile) : false end end
# File lib/fakefs/file.rb, line 35 def self.join(*parts) RealFile.join(parts) end
# File lib/fakefs/file.rb, line 173 def self.link(source, dest) if directory?(source) raise Errno::EPERM, "Operation not permitted - #{source} or #{dest}" end if !exists?(source) raise Errno::ENOENT, "No such file or directory - #{source} or #{dest}" end if exists?(dest) raise Errno::EEXIST, "File exists - #{source} or #{dest}" end source = FileSystem.find(source) dest = FileSystem.add(dest, source.entry.clone) source.link(dest) 0 end
# File lib/fakefs/file.rb, line 219 def self.lstat(file) File::Stat.new(file, true) end
# File lib/fakefs/file.rb, line 56 def self.mtime(path) if exists?(path) FileSystem.find(path).mtime else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 265 def initialize(path, mode = READ_ONLY, perm = nil) @path = path @mode = mode @file = FileSystem.find(path) @autoclose = true check_modes! file_creation_mode? ? create_missing_file : check_file_existence! super(@file.content, mode) end
# File lib/fakefs/file.rb, line 143 def self.read(path) file = new(path) if file.exists? file.read else raise Errno::ENOENT end end
Assuming that everyone can read and write files
# File lib/fakefs/file.rb, line 152 def self.readlines(path) read(path).split("\n") end
# File lib/fakefs/file.rb, line 138 def self.readlink(path) symlink = FileSystem.find(path) symlink.target end
# File lib/fakefs/file.rb, line 156 def self.rename(source, dest) if directory?(source) && file?(dest) raise Errno::ENOTDIR, "Not a directory - #{source} or #{dest}" elsif file?(source) && directory?(dest) raise Errno::EISDIR, "Is a directory - #{source} or #{dest}" end if target = FileSystem.find(source) FileSystem.add(dest, target.entry.clone) FileSystem.delete(source) else raise Errno::ENOENT, "No such file or directory - #{source} or #{dest}" end 0 end
# File lib/fakefs/file.rb, line 84 def self.size(path) read(path).length end
# File lib/fakefs/file.rb, line 88 def self.size?(path) if exists?(path) && !size(path).zero? true else nil end end
# File lib/fakefs/file.rb, line 223 def self.split(path) return RealFile.split(path) end
# File lib/fakefs/file.rb, line 215 def self.stat(file) File::Stat.new(file) end
# File lib/fakefs/file.rb, line 211 def self.symlink(source, dest) FileUtils.ln_s(source, dest) end
# File lib/fakefs/file.rb, line 109 def self.symlink?(path) if path.respond_to? :entry path.is_a? FakeSymlink else FileSystem.find(path).is_a? FakeSymlink end end
# File lib/fakefs/file.rb, line 72 def self.utime(atime, mtime, *paths) paths.each do |path| if exists?(path) FileSystem.find(path).mtime = mtime else raise Errno::ENOENT end end paths.size end
# File lib/fakefs/file.rb, line 328 def atime raise NotImplementedError end
# File lib/fakefs/file.rb, line 373 def autoclose? @autoclose end
# File lib/fakefs/file.rb, line 353 def binmode? raise NotImplementedError end
# File lib/fakefs/file.rb, line 332 def chmod(mode_int) raise NotImplementedError end
# File lib/fakefs/file.rb, line 336 def chown(owner_int, group_int) raise NotImplementedError end
# File lib/fakefs/file.rb, line 357 def close_on_exec=(bool) raise NotImplementedError end
# File lib/fakefs/file.rb, line 361 def close_on_exec? raise NotImplementedError end
# File lib/fakefs/file.rb, line 340 def ctime self.class.ctime(@path) end
# File lib/fakefs/file.rb, line 278 def exists? true end
# File lib/fakefs/file.rb, line 344 def flock(locking_constant) raise NotImplementedError end
# File lib/fakefs/file.rb, line 293 def ioctl(integer_cmd, arg) raise NotImplementedError end
# File lib/fakefs/file.rb, line 305 def lstat self.class.lstat(@path) end
# File lib/fakefs/file.rb, line 348 def mtime self.class.mtime(@path) end
# File lib/fakefs/file.rb, line 297 def read_nonblock(maxlen, outbuf = nil) raise NotImplementedError end
# File lib/fakefs/file.rb, line 324 def readpartial(maxlen, outbuf = nil) raise NotImplementedError end
# File lib/fakefs/file.rb, line 379 def size File.size(@path) end
# File lib/fakefs/file.rb, line 301 def stat self.class.stat(@path) end
# File lib/fakefs/file.rb, line 309 def sysseek(position, whence = SEEK_SET) seek(position, whence) pos end
# File lib/fakefs/file.rb, line 316 def to_io self end
# File lib/fakefs/file.rb, line 365 def to_path @path end
# File lib/fakefs/file.rb, line 320 def write_nonblock(string) raise NotImplementedError end