Class: RightScale::Platform::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/right_agent/platform/linux.rb,
lib/right_agent/platform/darwin.rb,
lib/right_agent/platform/windows.rb

Constant Summary collapse

MAX_PATH =
260
@@get_temp_dir_api =
nil

Instance Method Summary collapse

Constructor Details

#initializeFilesystem

Returns a new instance of Filesystem.



85
86
87
# File 'lib/right_agent/platform/windows.rb', line 85

def initialize
  @temp_dir = nil
end

Instance Method Details

#cache_dirObject

Cache directory for the current platform



179
180
181
# File 'lib/right_agent/platform/windows.rb', line 179

def cache_dir
  '/var/cache'
end

#cfg_dirObject

Deprecated.

Directory containing generated agent configuration files



119
120
121
122
# File 'lib/right_agent/platform/linux.rb', line 119

def cfg_dir
  warn "cfg_dir is deprecated; please use right_agent_cfg_dir"
  right_agent_cfg_dir
end

#company_program_files_dirObject

specific to the windows environment to aid in resolving paths to executables in test scenarios.



249
250
251
# File 'lib/right_agent/platform/windows.rb', line 249

def company_program_files_dir
  return pretty_path(File.join(Dir::PROGRAM_FILES, 'RightScale'))
end

Ruby 1.8.7 on Windows does not support File.symlink. Windows Vista and newer versions of Windows do support symlinks via CreateSymbolicLink, so we will use CreateSymbolicLink if it is available, otherwise throw (on 2003 and earlier)

Parameters

old_name (String)

the path to the real file/directory

new_name (String)

the path to the link

Results

always 0 as does File.symlink

Raises

Win32Error

if failed to create the link

PlatformNotSupported

if the current platform does not support the CreateSymbolicLink API



197
198
199
# File 'lib/right_agent/platform/linux.rb', line 197

def create_symlink(old_name, new_name)
  File.symlink(old_name, new_name)
end

#ensure_local_drive_path(path, temp_dir_name) ⇒ Object

Ensures a local drive location for the file or folder given by path by copying to a local temp directory given by name only if the item does not appear on the home drive. This method is useful because secure applications refuse to run scripts from network locations, etc. Replaces any similar files in temp dir to ensure latest updates.

Parameters

path(String)

path to file or directory to be placed locally.

temp_dir_name(String)

name (or relative path) of temp directory to

use only if the file or folder is not on a local drive.

Returns

result(String)

local drive path



192
193
194
# File 'lib/right_agent/platform/linux.rb', line 192

def ensure_local_drive_path(path, temp_dir_name)
  return path
end

#find_executable_in_path(command_name) ⇒ Object

Finds the given command name in the PATH. this emulates the ‘which’ command from linux (without the terminating newline).

Parameters

command_name(String)

Name of command to be tested with

or without the expected windows file extension.

Return

path to first matching executable file in PATH or nil



109
110
111
112
113
114
115
# File 'lib/right_agent/platform/linux.rb', line 109

def find_executable_in_path(command_name)
  ENV['PATH'].split(/;|:/).each do |dir|
    path = File.join(dir, command_name)
    return path if File.executable?(path)
  end
  return nil
end

#has_executable_in_path(command_name) ⇒ Object

Is given command available in the PATH?

Parameters

command_name(String)

Name of command to be tested with

or without the expected windows file extension.

Return

true

If command is in path

false

Otherwise



97
98
99
# File 'lib/right_agent/platform/linux.rb', line 97

def has_executable_in_path(command_name)
  return nil != find_executable_in_path(command_name)
end

#log_dirObject

Log directory for the current platform



184
185
186
# File 'lib/right_agent/platform/windows.rb', line 184

def log_dir
  '/var/log'
end

#long_path_to_short_path(long_path) ⇒ Object

converts a long path to a short path. in windows terms, this means taking any file/folder name over 8 characters in length and truncating it to 6 characters with ~1..~n appended depending on how many similar names exist in the same directory. file extensions are simply chopped at three letters. the short name is equivalent for all API calls to the long path but requires no special quoting, etc. the path must exist at least partially for the API call to succeed.

Parameters

long_path(String)

fully or partially existing long path to be

converted to its short path equivalent.

Return

short_path(String)

short path equivalent or same path if non-existent



182
183
184
# File 'lib/right_agent/platform/linux.rb', line 182

def long_path_to_short_path(long_path)
  return long_path
end

#pid_dirObject

Path to place pid files



168
169
170
# File 'lib/right_agent/platform/linux.rb', line 168

def pid_dir
  '/var/run'
end

#pretty_path(path, native_fs_flag = false) ⇒ Object

pretties up paths which assists Dir.glob() and Dir[] calls which will return empty if the path contains any \ characters. windows doesn’t care (most of the time) about whether you use \ or / in paths. as always, there are exceptions to this rule (such as “del c:/xyz” which fails while “del c:xyz” succeeds)

Parameters

path(String)

path to make pretty

native_fs_flag(Boolean)

true if path is pretty for native file

system (i.e. file system calls more likely to succeed), false if
pretty for Ruby interpreter (default).


187
188
189
# File 'lib/right_agent/platform/linux.rb', line 187

def pretty_path(path, native_fs_flag = false)
  return path
end

#private_bin_dirObject

Path to right link configuration and internal usage scripts



173
174
175
# File 'lib/right_agent/platform/linux.rb', line 173

def private_bin_dir
  '/opt/rightscale/bin'
end

#right_agent_cfg_dirObject

Directory containing generated agent configuration files



132
133
134
# File 'lib/right_agent/platform/linux.rb', line 132

def right_agent_cfg_dir
  '/var/lib/rightscale/right_agent'
end

Dynamic, persistent runtime state that is specific to RightLink



147
148
149
# File 'lib/right_agent/platform/linux.rb', line 147

def right_link_dynamic_state_dir
  '/var/lib/rightscale/right_link'
end


207
208
209
210
211
212
213
# File 'lib/right_agent/platform/windows.rb', line 207

def right_link_home_dir
  unless @right_link_home_dir
    @right_link_home_dir = ENV['RS_RIGHT_LINK_HOME'] ||
                           File.normalize_path(File.join(company_program_files_dir, 'RightLink'))
  end
  @right_link_home_dir
end

Static (time-invariant) state that is specific to RightLink



142
143
144
# File 'lib/right_agent/platform/linux.rb', line 142

def right_link_static_state_dir
  '/etc/rightscale.d/right_link'
end

#right_scale_state_dirObject

Deprecated.

RightScale state directory for the current platform



126
127
128
129
# File 'lib/right_agent/platform/linux.rb', line 126

def right_scale_state_dir
  warn "right_scale_state_dir is deprecated; please use either right_scale_static_state_dir or right_agent_dynamic_state_dir"
  right_scale_static_state_dir
end

#right_scale_static_state_dirObject

Static (time-invariant) state that is common to all RightScale apps/agents



137
138
139
# File 'lib/right_agent/platform/linux.rb', line 137

def right_scale_static_state_dir
  '/etc/rightscale.d'
end

#sandbox_dirObject



177
178
179
# File 'lib/right_agent/platform/linux.rb', line 177

def sandbox_dir
  '/opt/rightscale/sandbox'
end

#spool_dirObject

Spool directory for the current platform



174
175
176
# File 'lib/right_agent/platform/windows.rb', line 174

def spool_dir
  '/var/spool'
end

#system_rootObject

System root path



225
226
227
# File 'lib/right_agent/platform/windows.rb', line 225

def system_root
  return pretty_path(ENV['SystemRoot'])
end

#temp_dirObject

Temp directory for the current platform



189
190
191
# File 'lib/right_agent/platform/windows.rb', line 189

def temp_dir
  '/tmp'
end