mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Don't remove API file socket if it exists and it's usable
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user