Skip to content

Commit

Permalink
Don't remove API file socket if it exists and it's usable
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Jan 19, 2019
1 parent 3b5840e commit 22848b0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/api_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,25 @@ func aptlyAPIServe(cmd *commander.Command, args []string) error {
listenURL, err := url.Parse(listen)
if err == nil && listenURL.Scheme == "unix" {
file := listenURL.Path
os.Remove(file)

var stat os.FileInfo
stat, err = os.Stat(file)
shouldRemove := true

if err == nil && stat.Mode()&os.ModeSocket == os.ModeSocket {
shouldRemove = false
}

if err != nil && os.IsNotExist(err) {
shouldRemove = false
}

if shouldRemove {
err = os.Remove(file)
if err != nil {
fmt.Printf("Warning: error removing file %s: %s\n", file, err)
}
}

var listener net.Listener
listener, err = net.Listen("unix", file)
Expand Down

0 comments on commit 22848b0

Please sign in to comment.