Module: Dkdeploy::Helpers::FileSystem
- Defined in:
- lib/dkdeploy/helpers/file_system.rb
Overview
Class for the capistrano copy
Instance Method Summary collapse
-
#apply_file_access_permissions(context, host, path, access_properties, force_recursive = false) ⇒ Object
Applies file owner/group/mode permissions to path on host via Capistrano - optionally recursively.
-
#map_path_in_release_or_shared_path(release_or_shared_path, path) ⇒ String
Adds the absolute path prefix to the given relative path depending whether this needs to be in shared or release path.
-
#merge_paths_with_resolved_symlinks(context, *paths) ⇒ Array
The merged array with paths.
-
#resolve_path_if_symlink(context, path) ⇒ String
Resolves the symlink path to its target, otherwise returns the path without any changing Note: the function can only be run within SSHKit context.
Instance Method Details
#apply_file_access_permissions(context, host, path, access_properties, force_recursive = false) ⇒ Object
Applies file owner/group/mode permissions to path on host via Capistrano - optionally recursively
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dkdeploy/helpers/file_system.rb', line 47 def (context, host, path, access_properties, force_recursive = false) # rubocop:disable Metrics/AbcSize unless context.test " [ -e #{path} ] " context.error I18n.t('resource.not_exists_on_host', resource: path, host: host.hostname, scope: :dkdeploy) return end # if the access properties should be applied recursively recursive = access_properties.fetch(:recursive, false) || force_recursive recursive = recursive ? '-R' : '' resolved_path = resolve_path_if_symlink(context, path) # change owner if set if access_properties.key?(:owner) context.execute :chown, recursive, access_properties.fetch(:owner), resolved_path end # change group if set if access_properties.key?(:group) context.execute :chgrp, recursive, access_properties.fetch(:group), resolved_path end # change mode if set if access_properties.key?(:mode) # rubocop:disable Style/GuardClause context.execute :chmod, recursive, access_properties.fetch(:mode), resolved_path end end |
#map_path_in_release_or_shared_path(release_or_shared_path, path) ⇒ String
Adds the absolute path prefix to the given relative path depending whether this needs to be in shared or release path.
13 14 15 16 |
# File 'lib/dkdeploy/helpers/file_system.rb', line 13 def map_path_in_release_or_shared_path(release_or_shared_path, path) prefix_path = release_or_shared_path == :shared_path ? shared_path : release_path prefix_path.join(path) end |
#merge_paths_with_resolved_symlinks(context, *paths) ⇒ Array
Returns the merged array with paths.
38 39 40 41 42 43 44 |
# File 'lib/dkdeploy/helpers/file_system.rb', line 38 def merge_paths_with_resolved_symlinks(context, *paths) paths.each do |path| resolved_path = resolve_path_if_symlink context, path paths.push resolved_path unless paths.include? resolved_path end paths end |
#resolve_path_if_symlink(context, path) ⇒ String
Resolves the symlink path to its target, otherwise returns the path without any changing Note: the function can only be run within SSHKit context
24 25 26 27 28 29 |
# File 'lib/dkdeploy/helpers/file_system.rb', line 24 def resolve_path_if_symlink(context, path) if context.test " [ -L #{path} ] " return context.capture :readlink, '-f', path end path end |