Always pass basename to install_p

Currently, when called with one argument, dst is set to self, i.e. the
directory into which the source file should be moved.

When called with a second argument (for renames), dst is the full path,
including the basename, to the moved file.

Instead, let's always pass the full path, which means we can remove the
branching logic around computing dst.
This commit is contained in:
Jack Nagel 2015-03-23 21:03:55 -04:00
parent 453990f1aa
commit 6f0efd6f3d
2 changed files with 6 additions and 13 deletions

View File

@ -21,28 +21,23 @@ class Pathname
opoo "tried to install empty array to #{self}" opoo "tried to install empty array to #{self}"
return return
end end
src.each {|s| install_p(s) } src.each { |s| install_p(s, File.basename(s)) }
when Hash when Hash
if src.empty? if src.empty?
opoo "tried to install empty hash to #{self}" opoo "tried to install empty hash to #{self}"
return return
end end
src.each {|s, new_basename| install_p(s, new_basename) } src.each { |s, new_basename| install_p(s, new_basename) }
else else
install_p(src) install_p(src, File.basename(src))
end end
end end
end end
def install_p src, new_basename = nil def install_p(src, new_basename)
raise Errno::ENOENT, src.to_s unless File.symlink?(src) || File.exist?(src) raise Errno::ENOENT, src.to_s unless File.symlink?(src) || File.exist?(src)
if new_basename dst = join(new_basename)
new_basename = File.basename(new_basename) # rationale: see Pathname.+
dst = self+new_basename
else
dst = self
end
src = src.to_s src = src.to_s
dst = dst.to_s dst = dst.to_s

View File

@ -1,8 +1,6 @@
module InstallRenamed module InstallRenamed
def install_p _, new_basename = nil def install_p(_, new_basename)
super do |src, dst| super do |src, dst|
dst += "/#{File.basename(src)}" if File.directory? dst
if File.directory? src if File.directory? src
Pathname.new(dst).install Dir["#{src}/*"] Pathname.new(dst).install Dir["#{src}/*"]
next next