Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
guange
brew
Commits
99df82c5
Commit
99df82c5
authored
15 years ago
by
Max Howell
Committed by
Adam Vandenberg
15 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixes Pathname.install(:foo => :bar) to work when File.exist?(:bar)
parent
3927972a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Library/Homebrew/extend/pathname.rb
+38
-26
38 additions, 26 deletions
Library/Homebrew/extend/pathname.rb
with
38 additions
and
26 deletions
Library/Homebrew/extend/pathname.rb
+
38
−
26
View file @
99df82c5
...
...
@@ -3,14 +3,27 @@ require 'pathname'
# we enhance pathname to make our code more readable
class
Pathname
def
install
src
if
src
.
is_a?
Array
src
.
collect
{
|
src
|
install
src
}
elsif
src
.
is_a?
Hash
src
.
each_pair
do
|
name
,
new_name
|
FileUtils
.
mv
name
,
new_name
install
new_name
case
src
when
Array
src
.
collect
{
|
src
|
install_p
(
src
)
}
when
Hash
src
.
collect
{
|
src
,
new_basename
|
install_p
(
src
,
new_basename
)
}
else
install_p
(
src
)
end
end
def
install_p
src
,
new_basename
=
nil
if
new_basename
new_basename
=
File
.
basename
(
new_basename
)
# rationale: see Pathname.+
dst
=
self
+
new_basename
else
dst
=
self
end
src
=
src
.
to_s
dst
=
dst
.
to_s
# if it's a symlink, don't resolve it to a file because if we are moving
# files one by one, it's likely we will break the symlink by moving what
# it points to before we move it
...
...
@@ -21,15 +34,14 @@ class Pathname
if
File
.
symlink?
src
# we use the BSD mv command because FileUtils copies the target and
# not the link! I'm beginning to wish I'd used Python quite honestly!
raise
unless
Kernel
.
system
'mv'
,
src
,
to_s
and
$?
==
0
raise
unless
Kernel
.
system
'mv'
,
src
,
dst
else
# we mv when possible as it is faster and you should only be using
# this function when installing from the temporary build directory
FileUtils
.
mv
src
,
to_s
end
src
=
Pathname
.
new
src
return
self
+
src
.
basename
FileUtils
.
mv
src
,
dst
end
return
Pathname
.
new
(
dst
)
end
# we assume this pathname object is a file obviously
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment