Class: U3dCore::AdminTools
- Inherits:
-
Object
- Object
- U3dCore::AdminTools
- Defined in:
- lib/u3d_core/admin_tools.rb
Class Method Summary collapse
- .create_file(os, path, dry_run: false) ⇒ Object
-
.move_file(source_path, new_path, command, dry_run: false) ⇒ Object
move one path to a new path.
- .move_os_file(os, source_path, new_path, dry_run:) ⇒ Object
Class Method Details
.create_file(os, path, dry_run: false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/u3d_core/admin_tools.rb', line 36 def self.create_file(os, path, dry_run: false) if dry_run UI. "'#{source_path}' would create file at '#{path}'" return end if os == :win path = U3dCore::Helper.windows_path(path) command = "fsutil file createnew #{path.argescape} 0" else command = "touch #{path.shellescape}" end U3dCore::CommandExecutor.execute(command: command, admin: true) true end |
.move_file(source_path, new_path, command, dry_run: false) ⇒ Object
move one path to a new path
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/u3d_core/admin_tools.rb', line 53 def self.move_file(source_path, new_path, command, dry_run: false) if source_path == new_path UI.verbose "move_file does nothing if the path won't change (#{source_path})" return false end if dry_run UI. "'#{source_path}' would move to '#{new_path}'" else UI.important "Moving '#{source_path}' to '#{new_path}'..." U3dCore::CommandExecutor.execute(command: command, admin: true) UI.success "Successfully moved '#{source_path}' to '#{new_path}'" end true rescue StandardError => e UI.error "Unable to move '#{source_path}' to '#{new_path}': #{e}" false end |
.move_os_file(os, source_path, new_path, dry_run:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/u3d_core/admin_tools.rb', line 25 def self.move_os_file(os, source_path, new_path, dry_run:) if os == :win source_path = U3dCore::Helper.windows_path(source_path) new_path = U3dCore::Helper.windows_path(new_path) command = "move #{source_path.argescape} #{new_path.argescape}" else command = "mv #{source_path.shellescape} #{new_path.shellescape}" end move_file(source_path, new_path, command, dry_run: dry_run) end |