# File lib/fakefs/file.rb, line 70 def self.atime(path) if exists?(path) FileSystem.find(path).atime else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 137 def self.basename(*args) RealFile.basename(*args) end
# File lib/fakefs/file.rb, line 235 def self.chmod(mode_int, filename) FileSystem.find(filename).mode = 0100000 + mode_int end
# File lib/fakefs/file.rb, line 239 def self.chown(owner_int, group_int, filename) file = FileSystem.find(filename) if owner_int && owner_int != -1 owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer" file.uid = owner_int end if group_int && group_int != -1 group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer" file.gid = group_int end end
# File lib/fakefs/file.rb, line 103 def self.const_missing(name) RealFile.const_get(name) end
# File lib/fakefs/file.rb, line 62 def self.ctime(path) if exists?(path) FileSystem.find(path).ctime else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 201 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 107 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 141 def self.dirname(path) RealFile.dirname(path) end
# File lib/fakefs/file.rb, line 37 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 133 def self.expand_path(*args) RealFile.expand_path(*args) end
# File lib/fakefs/file.rb, line 29 def self.extname(path) RealFile.extname(path) end
# File lib/fakefs/file.rb, line 124 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 33 def self.join(*parts) RealFile.join(parts) end
# File lib/fakefs/file.rb, line 181 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 227 def self.lstat(file) File::Stat.new(file, true) end
# File lib/fakefs/file.rb, line 54 def self.mtime(path) if exists?(path) FileSystem.find(path).mtime else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 315 def initialize(path, mode = READ_ONLY, perm = nil) @path = path @mode = mode.is_a?(Hash) ? (mode[:mode] || READ_ONLY) : 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 150 def self.read(path, *args) file = new(path) if file.exists? FileSystem.find(path).atime = Time.now file.read else raise Errno::ENOENT end end
# File lib/fakefs/file.rb, line 160 def self.readlines(path) read(path).split("\n") end
# File lib/fakefs/file.rb, line 145 def self.readlink(path) symlink = FileSystem.find(path) symlink.target end
# File lib/fakefs/file.rb, line 164 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 91 def self.size(path) read(path).length end
# File lib/fakefs/file.rb, line 95 def self.size?(path) if exists?(path) && !size(path).zero? true else nil end end
# File lib/fakefs/file.rb, line 231 def self.split(path) return RealFile.split(path) end
# File lib/fakefs/file.rb, line 223 def self.stat(file) File::Stat.new(file) end
# File lib/fakefs/file.rb, line 219 def self.symlink(source, dest) FileUtils.ln_s(source, dest) end
# File lib/fakefs/file.rb, line 116 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 251 def self.umask RealFile.umask end
# File lib/fakefs/file.rb, line 78 def self.utime(atime, mtime, *paths) paths.each do |path| if exists?(path) FileSystem.find(path).atime = atime FileSystem.find(path).mtime = mtime else raise Errno::ENOENT end end paths.size end
# File lib/fakefs/file.rb, line 461 def advise(advice, offset=0, len=0) end
# File lib/fakefs/file.rb, line 389 def atime self.class.atime(@path) end
# File lib/fakefs/file.rb, line 449 def autoclose=(autoclose) @autoclose = autoclose end
# File lib/fakefs/file.rb, line 441 def autoclose? @autoclose end
# File lib/fakefs/file.rb, line 421 def binmode? raise NotImplementedError end
# File lib/fakefs/file.rb, line 405 def chmod(mode_int) @file.mode = 0100000 + mode_int end
# File lib/fakefs/file.rb, line 409 def chown(owner_int, group_int) if owner_int && owner_int != -1 owner_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer" @file.uid = owner_int end if group_int && group_int != -1 group_int.is_a?(Fixnum) or raise TypeError, "can't convert String into Integer" @file.gid = group_int end end
# File lib/fakefs/file.rb, line 425 def close_on_exec=(bool) raise NotImplementedError end
# File lib/fakefs/file.rb, line 429 def close_on_exec? raise NotImplementedError end
# File lib/fakefs/file.rb, line 393 def ctime self.class.ctime(@path) end
# File lib/fakefs/file.rb, line 328 def exists? true end
# File lib/fakefs/file.rb, line 397 def flock(locking_constant) raise NotImplementedError end
# File lib/fakefs/file.rb, line 354 def ioctl(integer_cmd, arg) raise NotImplementedError end
# File lib/fakefs/file.rb, line 366 def lstat self.class.lstat(@path) end
# File lib/fakefs/file.rb, line 401 def mtime self.class.mtime(@path) end
# File lib/fakefs/file.rb, line 358 def read_nonblock(maxlen, outbuf = nil) raise NotImplementedError end
# File lib/fakefs/file.rb, line 385 def readpartial(maxlen, outbuf = nil) raise NotImplementedError end
# File lib/fakefs/file.rb, line 455 def size File.size(@path) end
# File lib/fakefs/file.rb, line 362 def stat self.class.stat(@path) end
# File lib/fakefs/file.rb, line 370 def sysseek(position, whence = SEEK_SET) seek(position, whence) pos end
# File lib/fakefs/file.rb, line 377 def to_io self end
# File lib/fakefs/file.rb, line 433 def to_path @path end
# File lib/fakefs/file.rb, line 332 def write(str) val = super(str) @file.mtime = Time.now val end
# File lib/fakefs/file.rb, line 381 def write_nonblock(string) raise NotImplementedError end
# File lib/fakefs/file.rb, line 471 def check_file_existence! raise Errno::ENOENT, @path unless @file end
# File lib/fakefs/file.rb, line 467 def check_modes! StringIO.new("", @mode) end
Create a missing file if the path is valid.
# File lib/fakefs/file.rb, line 489 def create_missing_file raise Errno::EISDIR, "Is a directory - #{path}" if File.directory?(@path) if !File.exists?(@path) # Unnecessary check, probably. dirname = RealFile.dirname @path unless dirname == "." dir = FileSystem.find dirname unless dir.kind_of? FakeDir raise Errno::ENOENT, "No such file or directory - #{path}" end end @file = FileSystem.add(path, FakeFile.new) end end
# File lib/fakefs/file.rb, line 475 def file_creation_mode? mode_in?(FILE_CREATION_MODES) || mode_in_bitmask?(FILE_CREATION_BITMASK) end
# File lib/fakefs/file.rb, line 479 def mode_in?(list) list.any? { |element| @mode.include?(element) } if @mode.respond_to?(:include?) end
# File lib/fakefs/file.rb, line 483 def mode_in_bitmask?(mask) (@mode & mask) != 0 if @mode.is_a?(Integer) end