Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
setup-ngninx-conf: replace brew prune
Browse files Browse the repository at this point in the history
`brew prune` has been deprecated and its replacement in Homebrew doesn't
do what we were using it for - removing dangling symlinks from Homebrew's
prefix without other side effects.

This reimplements a basic `brew prune`-alike that handles just any
dangling Nginx server symlinks, which is what we wanted from it.

Fixes #71.
  • Loading branch information
mistydemeo committed Jan 21, 2019
1 parent 4d9987a commit 5491ba3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/brew-setup-nginx-conf.rb
Expand Up @@ -3,6 +3,19 @@
require "erb"
require "pathname"

# Prunes invalid symlinks; an invalid project can lead
# to dangling symlinks in the Nginx root, which need
# to be removed.
def prune_dangling_symlinks_from prefix
base = Pathname.new(prefix)
base.children.select(&:symlink?).each do |symlink|
if !symlink.realpath.exist?
puts "Deleting invalid symlink: #{symlink}"
symlink.unlink
end
end
end

root_configuration = ARGV.delete "--root"
if root_configuration
http_port = 80
Expand Down Expand Up @@ -109,12 +122,14 @@
end
end

server = "/usr/local/etc/nginx/servers/#{name}"
server_base_path = "/usr/local/etc/nginx/servers"
server = File.join(server_base_path, name)
unless system "ln -sf '#{File.absolute_path(output)}' '#{server}'"
abort "Error: failed to symlink #{output} to #{server}!"
end

system "brew prune >/dev/null"
prune_dangling_symlinks_from server_base_path

unless started_services
unless system "brew services restart nginx >/dev/null"
abort "Error: failed to (re)start nginx!"
Expand Down

0 comments on commit 5491ba3

Please sign in to comment.