diff options
| author | Jack Nagel | 2014-07-04 17:22:58 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-07-04 17:46:52 -0500 |
| commit | 810b5838b21d6151f3ecc137c49b6519b215d327 (patch) | |
| tree | 5497493232df77c863ef7c58031363f2ad8d36bf /Library | |
| parent | f666b76c39f4f25d1dea9477cd9a69f0b46c2af1 (diff) | |
| download | brew-810b5838b21d6151f3ecc137c49b6519b215d327.tar.bz2 | |
Simpler "use the correct symlink" checks
When determining whether to remove a symlink during unlinking, we check
three things:
(a) Is the destination a symlink?
(b) Does the destination exist?
(c) Does the destination resolve to the source path?
However, since we know that the source path exists, (b) is guaranteed if
(a) and (c) are true. Thus checking (b) is unnecessary.
Similarly, when creating a new symlink during linking, we first check to
see if the link already exists by checking the same three criteria.
Again, checking (b) is unnecessary here.
See also the expanded test coverage in b52b579b.
Addendum: although we know that the source path exists during unlinking,
it doesn't matter. If the source path does not exist, then we still know
we have a broken symlink pointing into the keg we are unlinking, and
removing that symlink is still safe.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/keg.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index e80745a0b..6776335b7 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -192,7 +192,7 @@ class Keg dirs << dst if dst.directory? && !dst.symlink? # check whether the file to be unlinked is from the current keg first - next if !dst.symlink? || !dst.exist? || src != dst.resolved_path + next unless dst.symlink? && src == dst.resolved_path dst.uninstall_info if dst.to_s =~ INFOFILE_RX dst.unlink @@ -337,7 +337,7 @@ class Keg end def make_relative_symlink dst, src, mode - if dst.symlink? && dst.exist? && dst.resolved_path == src + if dst.symlink? && src == dst.resolved_path puts "Skipping; link already exists: #{dst}" if ARGV.verbose? return end |
