Class: RightScale::Platform::Filesystem

Inherits:
PlatformHelperBase show all
Defined in:
lib/right_agent/platform.rb,
lib/right_agent/platform/unix/platform.rb,
lib/right_agent/platform/windows/platform.rb,
lib/right_agent/platform/windows/mingw/platform.rb,
lib/right_agent/platform/windows/mswin/platform.rb

Overview

Declares various file system APIs.

Defined Under Namespace

Classes: API

Constant Summary collapse

MAX_PATH =

Windows-defined maximum path length for legacy Windows APIs that restrict path buffer sizes by default.

260
0x1
COMPANY_DIR_NAME =

this can change because companies get bought and managers insist on using the current company name for some reason (better learn that or else you will be finding and fixing all the hardcoded company names).

'RightScale'

Constants inherited from PlatformHelperBase

PlatformHelperBase::API_FALSE, PlatformHelperBase::API_NULL, PlatformHelperBase::API_TRUE, PlatformHelperBase::SIZEOF_DWORD, PlatformHelperBase::SIZEOF_QWORD, PlatformHelperBase::WIDE

Instance Method Summary collapse

Methods inherited from PlatformHelperBase

#copy_to_string_buffer, #with_unicode_buffer

Instance Method Details

#cache_dirObject

Overrides base Filesystem#cache_dir



328
329
330
# File 'lib/right_agent/platform.rb', line 328

def cache_dir
  must_be_overridden
end

#common_app_data_dirString

Convenience method for pretty common appdata dir and for mocking what is normally a Dir constant during test.

Returns:

  • (String)

    pretty common application data dir



288
289
290
# File 'lib/right_agent/platform/windows/platform.rb', line 288

def common_app_data_dir
  @common_app_data_dir ||= pretty_path(::Dir::COMMON_APPDATA)
end

#company_app_data_dirString

Common app data for all products of this company (whose name is not necessarily a constant because companies get bought, you know).

Returns:

  • (String)

    company common application data dir



304
305
306
# File 'lib/right_agent/platform/windows/platform.rb', line 304

def company_app_data_dir
  @company_app_data_dir ||= ::File.join(common_app_data_dir, COMPANY_DIR_NAME)
end

#company_program_files_dirString

Program files base for all products of this company.

Returns:

  • (String)

    path to installed RightScale directory



311
312
313
# File 'lib/right_agent/platform/windows/platform.rb', line 311

def company_program_files_dir
  @company_program_files_dir ||= ::File.join(program_files_dir, COMPANY_DIR_NAME)
end

Overrides base Filesystem#create_symlink

Ruby on Windows does not support File.symlink. Windows 2008 Server and newer versions of Windows do support the CreateSymbolicLink API.



419
420
421
# File 'lib/right_agent/platform.rb', line 419

def create_symlink(from_path, to_path)
  must_be_overridden
end

Overrides base Filesystem#CreateSymbolicLink



542
543
544
# File 'lib/right_agent/platform/windows/platform.rb', line 542

def CreateSymbolicLink(symlink_file_path, target_file_path, flags)
  must_be_overridden
end

#ensure_local_drive_path(path, temp_dir_name) ⇒ String

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)

    to file or directory to be placed locally

  • temp_dir_name (String)

    as relative path of temp directory to use only if the file or folder is not on a local drive.

Returns:

  • (String)

    local drive path



407
408
409
# File 'lib/right_agent/platform.rb', line 407

def ensure_local_drive_path(path, temp_dir_name)
  must_be_overridden
end

#find_executable_in_path(command_name) ⇒ Object

Overrides base Filesystem#find_executable_in_path



289
290
291
# File 'lib/right_agent/platform.rb', line 289

def find_executable_in_path(command_name)
  must_be_overridden
end

#GetShortPathName(long_path, short_path_buffer, short_path_buffer_length) ⇒ Object

Overrides base Filesystem#GetShortPathName



556
557
558
# File 'lib/right_agent/platform/windows/platform.rb', line 556

def GetShortPathName(long_path, short_path_buffer, short_path_buffer_length)
  must_be_overridden
end

#GetTempPath(buffer_length, buffer) ⇒ Object

Overrides base Filesystem#GetTempPath



569
570
571
# File 'lib/right_agent/platform/windows/platform.rb', line 569

def GetTempPath(buffer_length, buffer)
  must_be_overridden
end

#has_executable_in_path(command_name) ⇒ TrueClass|FalseClass

Is given command available in the PATH?

Parameters:

  • command_name (String)

    to be tested

Returns:

  • (TrueClass|FalseClass)

    true if command is in path



279
280
281
# File 'lib/right_agent/platform.rb', line 279

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

#log_dirObject

Overrides base Filesystem#log_dir



333
334
335
# File 'lib/right_agent/platform.rb', line 333

def log_dir
  must_be_overridden
end

#long_path_to_short_path(long_path) ⇒ Object

Overrides base Filesystem#long_path_to_short_path

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 six (6) characters with ~1..~n appended depending on how many similar names exist in the same directory. File extensions are simply chopped at three (3) letters. The short name is equivalent for all API calls to the long path but requires no special quoting, etc. Windows APIs are also subject to the MAX_PATH limitation (due to originally being designed to run on 16-bit DOS) unless special 32KB path extenders (i.e. prepending “\?" to input paths) are used. Converting paths from long to short paths makes file APIs alot less likely to fail with a path length error. Note that it is possible to configure an NTFS volume to not support short-paths (i.e. only long paths are kept by the file system) in which case this method will always return the long path (and probably lead to lots of path length errors).



377
378
379
# File 'lib/right_agent/platform.rb', line 377

def long_path_to_short_path(long_path)
  must_be_overridden
end

#pid_dirObject

Overrides base Filesystem#pid_dir



350
351
352
# File 'lib/right_agent/platform.rb', line 350

def pid_dir
  must_be_overridden
end

#pretty_path(path, native_fs_flag = false) ⇒ Object

Overrides base Filesystem#pretty_path

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)



391
392
393
# File 'lib/right_agent/platform.rb', line 391

def pretty_path(path, native_fs_flag = false)
  must_be_overridden
end

#private_bin_dirObject

Overrides base Filesystem#private_bin_dir



360
361
362
# File 'lib/right_agent/platform.rb', line 360

def private_bin_dir
  must_be_overridden
end

#program_files_dirString

Convenience method for pretty program files (x86) dir and for mocking what is normally a Dir constant during test.

Returns:

  • (String)

    pretty program files (x86) dir



296
297
298
# File 'lib/right_agent/platform/windows/platform.rb', line 296

def program_files_dir
  @program_files_dir ||= pretty_path(::Dir::PROGRAM_FILES)
end

#right_agent_cfg_dirObject

Overrides base Filesystem#right_agent_cfg_dir



294
295
296
# File 'lib/right_agent/platform.rb', line 294

def right_agent_cfg_dir
  must_be_overridden
end

Overrides base Filesystem#right_link_dynamic_state_dir



309
310
311
# File 'lib/right_agent/platform.rb', line 309

def right_link_dynamic_state_dir
  must_be_overridden
end

Returns installed RightLink directory path.

Returns:

  • (String)

    installed RightLink directory path



355
356
357
# File 'lib/right_agent/platform.rb', line 355

def right_link_home_dir
  must_be_overridden
end

Overrides base Filesystem#right_link_static_state_dir



304
305
306
# File 'lib/right_agent/platform.rb', line 304

def right_link_static_state_dir
  must_be_overridden
end

#right_scale_static_state_dirObject

Overrides base Filesystem#right_scale_static_state_dir



299
300
301
# File 'lib/right_agent/platform.rb', line 299

def right_scale_static_state_dir
  must_be_overridden
end

#sandbox_dirObject

Overrides base Filesystem#sandbox_dir



365
366
367
# File 'lib/right_agent/platform.rb', line 365

def sandbox_dir
  must_be_overridden
end

#source_code_dirObject

Overrides base Filesystem#source_code_dir



340
341
342
# File 'lib/right_agent/platform.rb', line 340

def source_code_dir
  must_be_overridden
end

#spool_dirObject

Overrides base Filesystem#spool_dir



314
315
316
# File 'lib/right_agent/platform.rb', line 314

def spool_dir
  must_be_overridden
end

#ssh_cfg_dirObject

Overrides base Filesystem#ssh_cfg_dir



319
320
321
# File 'lib/right_agent/platform.rb', line 319

def ssh_cfg_dir
  must_be_overridden
end

#system_rootString

Returns system root.

Returns:

  • (String)

    system root



316
317
318
# File 'lib/right_agent/platform/windows/platform.rb', line 316

def system_root
  @system_root ||= pretty_path(::ENV['SystemRoot'])
end

#temp_dirObject

Overrides base Filesystem#temp_dir



345
346
347
# File 'lib/right_agent/platform.rb', line 345

def temp_dir
  must_be_overridden
end

#user_home_dirString

Home directory for user settings and documents or else the temp dir if undefined.

Returns:

  • (String)

    user home



324
325
326
# File 'lib/right_agent/platform/windows/platform.rb', line 324

def user_home_dir
  @user_home_dir ||= pretty_path(::ENV['USERPROFILE'] || temp_dir)
end