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



342
343
344
# File 'lib/right_agent/platform.rb', line 342

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.



433
434
435
# File 'lib/right_agent/platform.rb', line 433

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



421
422
423
# File 'lib/right_agent/platform.rb', line 421

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



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

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



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

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

#log_dirObject

Overrides base Filesystem#log_dir



347
348
349
# File 'lib/right_agent/platform.rb', line 347

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).



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

def long_path_to_short_path(long_path)
  must_be_overridden
end

#pid_dirObject

Overrides base Filesystem#pid_dir



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

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)



405
406
407
# File 'lib/right_agent/platform.rb', line 405

def pretty_path(path, native_fs_flag = false)
  must_be_overridden
end

#private_bin_dirObject

Overrides base Filesystem#private_bin_dir



374
375
376
# File 'lib/right_agent/platform.rb', line 374

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



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

def right_agent_cfg_dir
  must_be_overridden
end

Overrides base Filesystem#right_link_dynamic_state_dir



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

def right_link_dynamic_state_dir
  must_be_overridden
end

Returns installed RightLink directory path.

Returns:

  • (String)

    installed RightLink directory path



369
370
371
# File 'lib/right_agent/platform.rb', line 369

def right_link_home_dir
  must_be_overridden
end

Overrides base Filesystem#right_link_static_state_dir



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

def right_link_static_state_dir
  must_be_overridden
end

#right_scale_static_state_dirObject

Overrides base Filesystem#right_scale_static_state_dir



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

def right_scale_static_state_dir
  must_be_overridden
end

#sandbox_dirObject

Overrides base Filesystem#sandbox_dir



379
380
381
# File 'lib/right_agent/platform.rb', line 379

def sandbox_dir
  must_be_overridden
end

#source_code_dirObject

Overrides base Filesystem#source_code_dir



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

def source_code_dir
  must_be_overridden
end

#spool_dirObject

Overrides base Filesystem#spool_dir



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

def spool_dir
  must_be_overridden
end

#ssh_cfg_dirObject

Overrides base Filesystem#ssh_cfg_dir



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

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



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

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