Methods
C
L
M
R
T
Instance Public methods
cd(dir)
This method is also aliased as chdir
# File lib/fakefs/fileutils.rb, line 124
    def cd(dir)
      FileSystem.chdir(dir)
    end
chdir(dir)

Alias for cd

chown(user, group, list, options={})
# File lib/fakefs/fileutils.rb, line 98
    def chown(user, group, list, options={})
      list = Array(list)
      list.each do |f|
        unless File.exists?(f)
          raise Errno::ENOENT, f
        end
      end
      list
    end
chown_R(user, group, list, options={})
# File lib/fakefs/fileutils.rb, line 108
    def chown_R(user, group, list, options={})
      chown(user, group, list, options={})
    end
cp(src, dest)
# File lib/fakefs/fileutils.rb, line 41
    def cp(src, dest)
      dst_file = FileSystem.find(dest)
      src_file = FileSystem.find(src)

      if !src_file
        raise Errno::ENOENT, src
      end

      if File.directory? src_file
        raise Errno::EISDIR, src
      end

      if dst_file && File.directory?(dst_file)
        FileSystem.add(File.join(dest, src), src_file.entry.clone(dst_file))
      else
        FileSystem.delete(dest)
        FileSystem.add(dest, src_file.entry.clone)
      end
    end
cp_r(src, dest)
# File lib/fakefs/fileutils.rb, line 61
    def cp_r(src, dest)
      # This error sucks, but it conforms to the original Ruby
      # method.
      raise "unknown file type: #{src}" unless dir = FileSystem.find(src)

      new_dir = FileSystem.find(dest)

      if new_dir && !File.directory?(dest)
        raise Errno::EEXIST, dest
      end

      if !new_dir && !FileSystem.find(dest+'/../')
        raise Errno::ENOENT, dest
      end

      # This last bit is a total abuse and should be thought hard
      # about and cleaned up.
      if new_dir
        if src[-2..-1] == '/.'
          dir.values.each{|f| new_dir[f.name] = f.clone(new_dir) }
        else
          new_dir[dir.name] = dir.entry.clone(new_dir)
        end
      else
        FileSystem.add(dest, dir.entry.clone)
      end
    end
ln_s(target, path, options = {})
# File lib/fakefs/fileutils.rb, line 32
    def ln_s(target, path, options = {})
      options = { :force => false }.merge(options)
      (FileSystem.find(path) and !options[:force]) ? raise(Errno::EEXIST, path) : FileSystem.delete(path)
      FileSystem.add(path, FakeSymlink.new(target))
    end
ln_sf(target, path)
# File lib/fakefs/fileutils.rb, line 37
    def ln_sf(target, path)
      ln_s(target, path, { :force => true })
    end
mkdir_p(path, options = {})
This method is also aliased as mkpath
# File lib/fakefs/fileutils.rb, line 5
    def mkdir_p(path, options = {})
      FileSystem.add(path, FakeDir.new)
    end
mkpath(path, options = {})

Alias for mkdir_p

mv(src, dest, options={})
# File lib/fakefs/fileutils.rb, line 89
    def mv(src, dest, options={})
      if target = FileSystem.find(src)
        FileSystem.add(dest, target.entry.clone)
        FileSystem.delete(src)
      else
        raise Errno::ENOENT, src
      end
    end
rm(list, options = {})
This method is also aliased as rm_rf rm_r rm_f
# File lib/fakefs/fileutils.rb, line 22
    def rm(list, options = {})
      Array(list).each do |path|
        FileSystem.delete(path)
      end
    end
rm_f(list, options = {})

Alias for rm

rm_r(list, options = {})

Alias for rm

rm_rf(list, options = {})

Alias for rm

rmdir(list, options = {})
# File lib/fakefs/fileutils.rb, line 10
    def rmdir(list, options = {})
      list = [ list ] unless list.is_a?(Array)
      list.each do |l|
        parent = l.split('/')
        parent.pop
        raise Errno::ENOENT, "No such file or directory - #{l}" unless parent.join == "" || FileSystem.find(parent.join('/'))
        raise Errno::ENOENT, l unless FileSystem.find(l)
        raise Errno::ENOTEMPTY, l unless FileSystem.find(l).values.empty?
        rm(l)
      end
    end
touch(list, options={})
# File lib/fakefs/fileutils.rb, line 112
    def touch(list, options={})
      Array(list).each do |f|
        directory = File.dirname(f)
        # FIXME this explicit check for '.' shouldn't need to happen
        if File.exists?(directory) || directory == '.'
          FileSystem.add(f, FakeFile.new)
        else
          raise Errno::ENOENT, f
        end
      end
    end