diff --git a/cmd/initprovider.go b/cmd/initprovider.go index 63325f75fd748cfd33d8e1904b253ad31cda0383..2b5f60695a4a1d753d3e713ab09bd88c77e652a0 100644 --- a/cmd/initprovider.go +++ b/cmd/initprovider.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "github.com/rs/zerolog" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -44,6 +46,7 @@ Please take a look at the usage below to customize the options.`, logger.DebugToConsole("Data provider successfully initialized") } else { logger.WarnToConsole("Unable to initialize data provider: %v", err) + os.Exit(1) } }, } diff --git a/cmd/install_windows.go b/cmd/install_windows.go index 8ae22e3124145d4902a46968ef62747c8f9d1c0b..fe964836135dc189d2097fb5c9dc3231720bb9b6 100644 --- a/cmd/install_windows.go +++ b/cmd/install_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "strconv" "github.com/spf13/cobra" @@ -42,6 +43,7 @@ Please take a look at the usage below to customize the startup options`, err := winService.Install(serviceArgs...) if err != nil { fmt.Printf("Error installing service: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service installed!\r\n") } diff --git a/cmd/portable.go b/cmd/portable.go index 6e6a0dbb2f45a09065406b6f9950d047a9d0ba09..94c96139d66afe67d1481eeb44f174b15b6fb115 100644 --- a/cmd/portable.go +++ b/cmd/portable.go @@ -73,12 +73,12 @@ Please take a look at the usage below to customize the serving parameters`, fi, err := os.Stat(portableGCSCredentialsFile) if err != nil { fmt.Printf("Invalid GCS credentials file: %v\n", err) - return + os.Exit(1) } if fi.Size() > 1048576 { fmt.Printf("Invalid GCS credentials file: %#v is too big %v/1048576 bytes\n", portableGCSCredentialsFile, fi.Size()) - return + os.Exit(1) } creds, err := ioutil.ReadFile(portableGCSCredentialsFile) if err != nil { @@ -135,7 +135,9 @@ Please take a look at the usage below to customize the serving parameters`, if err := service.StartPortableMode(portableSFTPDPort, portableSSHCommands, portableAdvertiseService, portableAdvertiseCredentials); err == nil { service.Wait() + os.Exit(0) } + os.Exit(1) }, } ) diff --git a/cmd/reload_windows.go b/cmd/reload_windows.go index 62eeb18962270335dec77fe3b1446449e750fbdf..d6a837579a60ec7d08b6e53a807e3635f85d4f9d 100644 --- a/cmd/reload_windows.go +++ b/cmd/reload_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" @@ -21,6 +22,7 @@ var ( err := s.Reload() if err != nil { fmt.Printf("Error reloading service: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service reloaded!\r\n") } diff --git a/cmd/serve.go b/cmd/serve.go index 8827c3ecbc08ccddbbe5e3265b65ccfdf703eb57..f785863203686d78773eecb0c359e4592dab25eb 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "github.com/spf13/cobra" "github.com/drakkan/sftpgo/service" @@ -31,7 +33,9 @@ Please take a look at the usage below to customize the startup options`, } if err := service.Start(); err == nil { service.Wait() + os.Exit(0) } + os.Exit(1) }, } ) diff --git a/cmd/start_windows.go b/cmd/start_windows.go index edd8e532fcbc9cf9c84adddbae82497d1f99b030..714051f8cba7e31386b53b93a915ae596324ef37 100644 --- a/cmd/start_windows.go +++ b/cmd/start_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "path/filepath" "github.com/spf13/cobra" @@ -37,6 +38,7 @@ var ( err := winService.RunService() if err != nil { fmt.Printf("Error starting service: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service started!\r\n") } diff --git a/cmd/status_windows.go b/cmd/status_windows.go index 03f77654f17f36cdc62c16772ed925b934084dac..fa6315b8ed469a0d9b81b6b06f15de032beb921b 100644 --- a/cmd/status_windows.go +++ b/cmd/status_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" @@ -21,6 +22,7 @@ var ( status, err := s.Status() if err != nil { fmt.Printf("Error querying service status: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service status: %#v\r\n", status.String()) } diff --git a/cmd/stop_windows.go b/cmd/stop_windows.go index 46660ee9fcb01d89b4094c35ab1a9b9e1e373312..93e4746599118ee92b33514a1ffdfcd2f9446c83 100644 --- a/cmd/stop_windows.go +++ b/cmd/stop_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" @@ -21,6 +22,7 @@ var ( err := s.Stop() if err != nil { fmt.Printf("Error stopping service: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service stopped!\r\n") } diff --git a/cmd/uninstall_windows.go b/cmd/uninstall_windows.go index e1d61a3e6880b9de322fdfda3f0d08467799e214..bcfeb00712119cae3d6ae08fedb8611c65d86094 100644 --- a/cmd/uninstall_windows.go +++ b/cmd/uninstall_windows.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" @@ -21,6 +22,7 @@ var ( err := s.Uninstall() if err != nil { fmt.Printf("Error removing service: %v\r\n", err) + os.Exit(1) } else { fmt.Printf("Service uninstalled\r\n") } diff --git a/dataprovider/bolt.go b/dataprovider/bolt.go index 8742d1a4760ac270e5fee3c12bfb9f35f1023524..044e664fbe68d7dbfd8bb59ce984fa6bce324f23 100644 --- a/dataprovider/bolt.go +++ b/dataprovider/bolt.go @@ -290,6 +290,10 @@ func (p BoltProvider) addUser(user User) error { return err } user.ID = int64(id) + user.LastQuotaUpdate = 0 + user.UsedQuotaSize = 0 + user.UsedQuotaFiles = 0 + user.LastLogin = 0 for _, folder := range user.VirtualFolders { err = addUserToFolderMapping(folder, user, folderBucket) if err != nil { diff --git a/dataprovider/memory.go b/dataprovider/memory.go index d825793c7895e2d40d1b5291ede687e315fc9fcc..dbbf7d1432710c50e653a3b3bc98400c987bcd41 100644 --- a/dataprovider/memory.go +++ b/dataprovider/memory.go @@ -192,6 +192,10 @@ func (p MemoryProvider) addUser(user User) error { return fmt.Errorf("username %#v already exists", user.Username) } user.ID = p.getNextID() + user.LastQuotaUpdate = 0 + user.UsedQuotaSize = 0 + user.UsedQuotaFiles = 0 + user.LastLogin = 0 user.VirtualFolders = p.joinVirtualFoldersFields(user) p.dbHandle.users[user.Username] = user p.dbHandle.usersIdx[user.ID] = user.Username diff --git a/httpd/httpd_test.go b/httpd/httpd_test.go index edfe5cd92c3b2ccced1aa250a027e1802c59387f..7b433d1b44e694f35180ba47ab94b0d98e764d81 100644 --- a/httpd/httpd_test.go +++ b/httpd/httpd_test.go @@ -738,7 +738,9 @@ func TestUserFolderMapping(t *testing.T) { u1 := getTestUser() u1.VirtualFolders = append(u1.VirtualFolders, vfs.VirtualFolder{ BaseVirtualFolder: vfs.BaseVirtualFolder{ - MappedPath: mappedPath1, + MappedPath: mappedPath1, + UsedQuotaFiles: 2, + UsedQuotaSize: 123, }, VirtualPath: "/vdir", QuotaSize: -1, @@ -753,6 +755,8 @@ func TestUserFolderMapping(t *testing.T) { folder := folders[0] assert.Len(t, folder.Users, 1) assert.Contains(t, folder.Users, user1.Username) + assert.Equal(t, 0, folder.UsedQuotaFiles) + assert.Equal(t, int64(0), folder.UsedQuotaSize) } u2 := getTestUser() u2.Username = defaultUsername + "2" @@ -793,7 +797,9 @@ func TestUserFolderMapping(t *testing.T) { user2.VirtualFolders = nil user2.VirtualFolders = append(user2.VirtualFolders, vfs.VirtualFolder{ BaseVirtualFolder: vfs.BaseVirtualFolder{ - MappedPath: mappedPath2, + MappedPath: mappedPath2, + UsedQuotaFiles: 2, + UsedQuotaSize: 123, }, VirtualPath: "/vdir", QuotaSize: 0, @@ -807,6 +813,8 @@ func TestUserFolderMapping(t *testing.T) { folder := folders[0] assert.Len(t, folder.Users, 1) assert.Contains(t, folder.Users, user2.Username) + assert.Equal(t, 0, folder.UsedQuotaFiles) + assert.Equal(t, int64(0), folder.UsedQuotaSize) } folders, _, err = httpd.GetFolders(0, 0, mappedPath1, http.StatusOK) assert.NoError(t, err)