Class: Puppet::FileSystem::File19Windows

Inherits:
File19 show all
Defined in:
lib/puppet/file_system/file19windows.rb

Constant Summary

Constants inherited from File

Puppet::FileSystem::File::IMPL

Instance Attribute Summary

Attributes inherited from File

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from File19

#binread

Methods inherited from File

#basename, #binread, #compare_stream, #dir, #each_line, #exclusive_open, #executable?, forget, #initialize, #mkpath, new, #open, overlay, #read, remember, #size, #to_s, #touch, #writable?

Constructor Details

This class inherits a constructor from Puppet::FileSystem::File

Class Method Details

.exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/file_system/file19windows.rb', line 6

def self.exist?(path)
  if ! Puppet.features.manages_symlinks?
    return ::File.exist?(path)
  end

  path = path.to_str if path.respond_to?(:to_str) # support WatchedFile
  path = path.to_s # support String and Pathname

  begin
    if Puppet::Util::Windows::File.symlink?(path)
      path = Puppet::Util::Windows::File.readlink(path)
    end
    ! Puppet::Util::Windows::File.stat(path).nil?
  rescue # generally INVALID_HANDLE_VALUE which means 'file not found'
    false
  end
end


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/puppet/file_system/file19windows.rb', line 60

def self.unlink(*file_names)
  if ! Puppet.features.manages_symlinks?
    return ::File.unlink(*file_names)
  end

  file_names.each do |file_name|
    file_name = file_name.to_s # handle PathName
    stat = Puppet::Util::Windows::File.stat(file_name) rescue nil

    # sigh, Ruby + Windows :(
    if stat && stat.ftype == 'directory'
      if Puppet::Util::Windows::File.symlink?(file_name)
        Dir.rmdir(file_name)
      else
        raise Errno::EPERM.new(file_name)
      end
    else
      ::File.unlink(file_name)
    end
  end

  file_names.length
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/puppet/file_system/file19windows.rb', line 24

def exist?
  self.class.exist?(@path)
end

#lstatObject



95
96
97
98
99
100
# File 'lib/puppet/file_system/file19windows.rb', line 95

def lstat
  if ! Puppet.features.manages_symlinks?
    return Puppet::Util::Windows::File.stat(@path)
  end
  Puppet::Util::Windows::File.lstat(@path)
end


55
56
57
58
# File 'lib/puppet/file_system/file19windows.rb', line 55

def readlink
  raise_if_symlinks_unsupported
  Puppet::Util::Windows::File.readlink(@path)
end

#statObject



88
89
90
91
92
93
# File 'lib/puppet/file_system/file19windows.rb', line 88

def stat
  if ! Puppet.features.manages_symlinks?
    return super
  end
  Puppet::Util::Windows::File.stat(@path)
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet/file_system/file19windows.rb', line 28

def symlink(dest, options = {})
  raise_if_symlinks_unsupported

  dest_exists = self.class.exist?(dest) # returns false on dangling symlink
  dest_stat = Puppet::Util::Windows::File.stat(dest) if dest_exists
  dest_symlink = Puppet::Util::Windows::File.symlink?(dest)

  # silent fail to preserve semantics of original FileUtils
  return 0 if dest_exists && dest_stat.ftype == 'directory'

  if dest_exists && dest_stat.ftype == 'file' && options[:force] != true
    raise(Errno::EEXIST, "#{dest} already exists and the :force option was not specified")
  end

  if options[:noop] != true
    ::File.delete(dest) if dest_exists # can only be file
    Puppet::Util::Windows::File.symlink(@path, dest)
  end

  0
end

#symlink?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/puppet/file_system/file19windows.rb', line 50

def symlink?
  return false if ! Puppet.features.manages_symlinks?
  Puppet::Util::Windows::File.symlink?(@path)
end


84
85
86
# File 'lib/puppet/file_system/file19windows.rb', line 84

def unlink
  self.class.unlink(@path)
end