Skip to content

Commit

Permalink
[FIXUP] Favor uri_to_local_path; delete mnt_point
Browse files Browse the repository at this point in the history
For MiqLocalMountSession, favor using uri_to_local_path when it does the
same thing as `File.join(mnt_point, relative_to_mount(remote_file))`,
which saves a decent amount of uncessary code by having to override
`mnt_point`.

This should behave the same on NFS and SMB as it did previously, but
then avoid the code changes for `mnt_point`, which isn't used terribly
consistently compared to the instance variable.

Ideally, we would want to use avoid the least amount of changes for
MiqGenericMountSession as well as the least amount of overrides in
MiqLocalMountSession, and I think this does that... I hope.
  • Loading branch information
NickLaMuro committed Sep 11, 2018
1 parent 8afe9f5 commit 7d5d866
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/gems/pending/util/mount/miq_generic_mount_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def download_single(remote_file, local_file)

begin
reconnect!
relpath = File.join(mnt_point, relative_to_mount(remote_file))
relpath = uri_to_local_path(remote_file)
unless File.exist?(relpath)
logger.warn("#{log_header} Remote file: [#{remote_file}] does not exist!")
return
Expand Down
28 changes: 4 additions & 24 deletions lib/gems/pending/util/mount/miq_local_mount_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,11 @@ def disconnect; end # :nodoc:
def mount_share; end # :nodoc:
# rubocop:enable Style/SingleLineMethods, Layout/EmptyLineBetweenDefs

def relative_to_mount(dest_uri) # :nodoc:
dest_uri
def relative_to_mount(remote_file) # :nodoc:
remote_file
end

def uri_to_local_path(dest_uri) # :nodoc:
File.expand_path(dest_uri)
end

# :nodoc:
#
# This is an override to allow methods that make use of `@mnt_point` to
# behave as we would expect them to.
#
# Determine the mount point relative to the destination file, and just remove
# the portions of the expanded path that already exist in the
# `remote_file_path` (might be everything if `remote_file_path` is a absolute
# path)
def mnt_point
@mnt_point ||= begin
path_str = if remote_file_path.kind_of?(IO)
remote_file_path.path
else
remote_file_path.to_s
end
File.expand_path(path_str).sub(path_str, "")
end
def uri_to_local_path(remote_file) # :nodoc:
File.expand_path(remote_file)
end
end

0 comments on commit 7d5d866

Please sign in to comment.