diff --git a/cmd/initprovider.go b/cmd/initprovider.go index 63325f75..2b5f6069 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 8ae22e31..fe964836 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 6e6a0dbb..94c96139 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 62eeb189..d6a83757 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 8827c3ec..f7858632 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 edd8e532..714051f8 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 03f77654..fa6315b8 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 46660ee9..93e47465 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 e1d61a3e..bcfeb007 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 8742d1a4..044e664f 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 d825793c..dbbf7d14 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 edfe5cd9..7b433d1b 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)