Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package main

import (
"bytes"
"crypto/md5"
"flag"
"io"
"io/ioutil"
Expand All @@ -23,6 +25,24 @@ var (
driver *server.Server
)

var deprecatedConfFileChecksum = md5.New().Sum([]byte(`{
"version": 1,
"accesses": [
{
"user": "test",
"pass": "test",
"fs": "os",
"params": {
"basePath": "/tmp"
}
}
],
"passive_transfer_port_range": {
"start": 2122,
"end": 2130
}
}`))

func main() {
// Arguments vars
var confFile string
Expand All @@ -48,9 +68,29 @@ func main() {
}

if autoCreate {
if _, err := os.Stat(confFile); err != nil && os.IsNotExist(err) {
logger.Warn("No conf file, creating one", "confFile", confFile)
shouldCreateOrUpdate := false
_, err := os.Stat(confFile)
if err != nil {
if os.IsNotExist(err) {
logger.Warn("No conf file, creating one", "confFile", confFile)
shouldCreateOrUpdate = true
}
} else {
file, errOpen := os.ReadFile(confFile)
if errOpen != nil {
logger.Error("Cannot open config file", "err", errOpen)
return
}

if bytes.Equal(md5.New().Sum(bytes.TrimSpace(file)), []byte(deprecatedConfFileChecksum)) {
logger.Warn("Deprecated conf file found, writing new conf")
shouldCreateOrUpdate = true
} else {
logger.Warn("Existing conf file is not same a deprecated one. No modifying.")
}
}

if shouldCreateOrUpdate {
if err := ioutil.WriteFile(confFile, confFileContent(), 0600); err != nil { //nolint: gomnd
logger.Warn("Couldn't create conf file", "confFile", confFile)
}
Expand Down