mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
parent
a587228cf0
commit
cc73bb811b
27 changed files with 188 additions and 187 deletions
|
@ -259,7 +259,7 @@ func (c *BaseConnection) CreateDir(virtualPath string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := fs.Mkdir(fsPath); err != nil {
|
if err := fs.Mkdir(fsPath); err != nil {
|
||||||
c.Log(logger.LevelWarn, "error creating dir: %#v error: %+v", fsPath, err)
|
c.Log(logger.LevelError, "error creating dir: %#v error: %+v", fsPath, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
vfs.SetPathPermissions(fs, fsPath, c.User.GetUID(), c.User.GetGID())
|
vfs.SetPathPermissions(fs, fsPath, c.User.GetUID(), c.User.GetGID())
|
||||||
|
@ -294,7 +294,7 @@ func (c *BaseConnection) RemoveFile(fs vfs.Fs, fsPath, virtualPath string, info
|
||||||
c.Log(logger.LevelDebug, "remove for path %#v handled by pre-delete action", fsPath)
|
c.Log(logger.LevelDebug, "remove for path %#v handled by pre-delete action", fsPath)
|
||||||
} else {
|
} else {
|
||||||
if err := fs.Remove(fsPath, false); err != nil {
|
if err := fs.Remove(fsPath, false); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to remove file/symlink %#v: %+v", fsPath, err)
|
c.Log(logger.LevelError, "failed to remove file/symlink %#v: %+v", fsPath, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,16 +358,16 @@ func (c *BaseConnection) RemoveDir(virtualPath string) error {
|
||||||
if fs.IsNotExist(err) && fs.HasVirtualFolders() {
|
if fs.IsNotExist(err) && fs.HasVirtualFolders() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.Log(logger.LevelWarn, "failed to remove a dir %#v: stat error: %+v", fsPath, err)
|
c.Log(logger.LevelError, "failed to remove a dir %#v: stat error: %+v", fsPath, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
if !fi.IsDir() || fi.Mode()&os.ModeSymlink != 0 {
|
if !fi.IsDir() || fi.Mode()&os.ModeSymlink != 0 {
|
||||||
c.Log(logger.LevelDebug, "cannot remove %#v is not a directory", fsPath)
|
c.Log(logger.LevelError, "cannot remove %#v is not a directory", fsPath)
|
||||||
return c.GetGenericError(nil)
|
return c.GetGenericError(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := fs.Remove(fsPath, true); err != nil {
|
if err := fs.Remove(fsPath, true); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to remove directory %#v: %+v", fsPath, err)
|
c.Log(logger.LevelError, "failed to remove directory %#v: %+v", fsPath, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
|
||||||
return c.GetGenericError(ErrQuotaExceeded)
|
return c.GetGenericError(ErrQuotaExceeded)
|
||||||
}
|
}
|
||||||
if err := fsSrc.Rename(fsSourcePath, fsTargetPath); err != nil {
|
if err := fsSrc.Rename(fsSourcePath, fsTargetPath); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to rename %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
c.Log(logger.LevelError, "failed to rename %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
||||||
return c.GetFsError(fsSrc, err)
|
return c.GetFsError(fsSrc, err)
|
||||||
}
|
}
|
||||||
vfs.SetPathPermissions(fsDst, fsTargetPath, c.User.GetUID(), c.User.GetGID())
|
vfs.SetPathPermissions(fsDst, fsTargetPath, c.User.GetUID(), c.User.GetGID())
|
||||||
|
@ -467,7 +467,7 @@ func (c *BaseConnection) CreateSymlink(virtualSourcePath, virtualTargetPath stri
|
||||||
return c.GetPermissionDeniedError()
|
return c.GetPermissionDeniedError()
|
||||||
}
|
}
|
||||||
if err := fs.Symlink(fsSourcePath, fsTargetPath); err != nil {
|
if err := fs.Symlink(fsSourcePath, fsTargetPath); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to create symlink %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
c.Log(logger.LevelError, "failed to create symlink %#v -> %#v: %+v", fsSourcePath, fsTargetPath, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
logger.CommandLog(symlinkLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1, "",
|
logger.CommandLog(symlinkLogSender, fsSourcePath, fsTargetPath, c.User.Username, "", c.ID, c.protocol, -1, -1, "",
|
||||||
|
@ -534,7 +534,7 @@ func (c *BaseConnection) handleChmod(fs vfs.Fs, fsPath, pathForPerms string, att
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := fs.Chmod(c.getRealFsPath(fsPath), attributes.Mode); err != nil {
|
if err := fs.Chmod(c.getRealFsPath(fsPath), attributes.Mode); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to chmod path %#v, mode: %v, err: %+v", fsPath, attributes.Mode.String(), err)
|
c.Log(logger.LevelError, "failed to chmod path %#v, mode: %v, err: %+v", fsPath, attributes.Mode.String(), err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
|
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
|
||||||
|
@ -550,7 +550,7 @@ func (c *BaseConnection) handleChown(fs vfs.Fs, fsPath, pathForPerms string, att
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := fs.Chown(c.getRealFsPath(fsPath), attributes.UID, attributes.GID); err != nil {
|
if err := fs.Chown(c.getRealFsPath(fsPath), attributes.UID, attributes.GID); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to chown path %#v, uid: %v, gid: %v, err: %+v", fsPath, attributes.UID,
|
c.Log(logger.LevelError, "failed to chown path %#v, uid: %v, gid: %v, err: %+v", fsPath, attributes.UID,
|
||||||
attributes.GID, err)
|
attributes.GID, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -572,7 +572,7 @@ func (c *BaseConnection) handleChtimes(fs vfs.Fs, fsPath, pathForPerms string, a
|
||||||
if errors.Is(err, vfs.ErrVfsUnsupported) && Config.SetstatMode == 2 {
|
if errors.Is(err, vfs.ErrVfsUnsupported) && Config.SetstatMode == 2 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.Log(logger.LevelWarn, "failed to chtimes for path %#v, access time: %v, modification time: %v, err: %+v",
|
c.Log(logger.LevelError, "failed to chtimes for path %#v, access time: %v, modification time: %v, err: %+v",
|
||||||
fsPath, attributes.Atime, attributes.Mtime, err)
|
fsPath, attributes.Atime, attributes.Mtime, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -615,7 +615,7 @@ func (c *BaseConnection) SetStat(virtualPath string, attributes *StatAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.truncateFile(fs, fsPath, virtualPath, attributes.Size); err != nil {
|
if err = c.truncateFile(fs, fsPath, virtualPath, attributes.Size); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to truncate path %#v, size: %v, err: %+v", fsPath, attributes.Size, err)
|
c.Log(logger.LevelError, "failed to truncate path %#v, size: %v, err: %+v", fsPath, attributes.Size, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
logger.CommandLog(truncateLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "",
|
logger.CommandLog(truncateLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1, "", "",
|
||||||
|
@ -803,7 +803,7 @@ func (c *BaseConnection) hasSpaceForCrossRename(fs vfs.Fs, quotaResult vfs.Quota
|
||||||
}
|
}
|
||||||
fi, err := fs.Lstat(sourcePath)
|
fi, err := fs.Lstat(sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "cross rename denied, stat error for path %#v: %v", sourcePath, err)
|
c.Log(logger.LevelError, "cross rename denied, stat error for path %#v: %v", sourcePath, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var sizeDiff int64
|
var sizeDiff int64
|
||||||
|
@ -818,7 +818,7 @@ func (c *BaseConnection) hasSpaceForCrossRename(fs vfs.Fs, quotaResult vfs.Quota
|
||||||
} else if fi.IsDir() {
|
} else if fi.IsDir() {
|
||||||
filesDiff, sizeDiff, err = fs.GetDirSize(sourcePath)
|
filesDiff, sizeDiff, err = fs.GetDirSize(sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "cross rename denied, error getting size for directory %#v: %v", sourcePath, err)
|
c.Log(logger.LevelError, "cross rename denied, error getting size for directory %#v: %v", sourcePath, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -915,7 +915,7 @@ func (c *BaseConnection) HasSpace(checkFiles, getUsage bool, requestPath string)
|
||||||
result.UsedFiles, result.UsedSize, err = dataprovider.GetUsedQuota(c.User.Username)
|
result.UsedFiles, result.UsedSize, err = dataprovider.GetUsedQuota(c.User.Username)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error getting used quota for %#v request path %#v: %v", c.User.Username, requestPath, err)
|
c.Log(logger.LevelError, "error getting used quota for %#v request path %#v: %v", c.User.Username, requestPath, err)
|
||||||
result.HasSpace = false
|
result.HasSpace = false
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -1066,7 +1066,7 @@ func (c *BaseConnection) updateQuotaAfterRename(fs vfs.Fs, virtualSourcePath, vi
|
||||||
if fi.Mode().IsDir() {
|
if fi.Mode().IsDir() {
|
||||||
numFiles, filesSize, err = fs.GetDirSize(targetPath)
|
numFiles, filesSize, err = fs.GetDirSize(targetPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to update quota after rename, error scanning moved folder %#v: %v",
|
c.Log(logger.LevelError, "failed to update quota after rename, error scanning moved folder %#v: %v",
|
||||||
targetPath, err)
|
targetPath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1074,7 +1074,7 @@ func (c *BaseConnection) updateQuotaAfterRename(fs vfs.Fs, virtualSourcePath, vi
|
||||||
filesSize = fi.Size()
|
filesSize = fi.Size()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.Log(logger.LevelWarn, "failed to update quota after rename, file %#v stat error: %+v", targetPath, err)
|
c.Log(logger.LevelError, "failed to update quota after rename, file %#v stat error: %+v", targetPath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if errSrc == nil && errDst == nil {
|
if errSrc == nil && errDst == nil {
|
||||||
|
|
|
@ -276,7 +276,7 @@ func (c *RetentionCheck) cleanupFolder(folderPath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
result.Error = fmt.Sprintf("unable to list directory %#v", folderPath)
|
result.Error = fmt.Sprintf("unable to list directory %#v", folderPath)
|
||||||
c.conn.Log(logger.LevelWarn, result.Error)
|
c.conn.Log(logger.LevelError, result.Error)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, info := range files {
|
for _, info := range files {
|
||||||
|
@ -285,7 +285,7 @@ func (c *RetentionCheck) cleanupFolder(folderPath string) error {
|
||||||
if err := c.cleanupFolder(virtualPath); err != nil {
|
if err := c.cleanupFolder(virtualPath); err != nil {
|
||||||
result.Elapsed = time.Since(startTime)
|
result.Elapsed = time.Since(startTime)
|
||||||
result.Error = fmt.Sprintf("unable to check folder: %v", err)
|
result.Error = fmt.Sprintf("unable to check folder: %v", err)
|
||||||
c.conn.Log(logger.LevelWarn, "unable to cleanup folder %#v: %v", virtualPath, err)
|
c.conn.Log(logger.LevelError, "unable to cleanup folder %#v: %v", virtualPath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -294,7 +294,7 @@ func (c *RetentionCheck) cleanupFolder(folderPath string) error {
|
||||||
if err := c.removeFile(virtualPath, info); err != nil {
|
if err := c.removeFile(virtualPath, info); err != nil {
|
||||||
result.Elapsed = time.Since(startTime)
|
result.Elapsed = time.Since(startTime)
|
||||||
result.Error = fmt.Sprintf("unable to remove file %#v: %v", virtualPath, err)
|
result.Error = fmt.Sprintf("unable to remove file %#v: %v", virtualPath, err)
|
||||||
c.conn.Log(logger.LevelWarn, "unable to remove file %#v, retention %v: %v",
|
c.conn.Log(logger.LevelError, "unable to remove file %#v, retention %v: %v",
|
||||||
virtualPath, retentionTime, err)
|
virtualPath, retentionTime, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ func (c *RetentionCheck) Start() {
|
||||||
for _, folder := range c.Folders {
|
for _, folder := range c.Folders {
|
||||||
if folder.Retention > 0 {
|
if folder.Retention > 0 {
|
||||||
if err := c.cleanupFolder(folder.Path); err != nil {
|
if err := c.cleanupFolder(folder.Path); err != nil {
|
||||||
c.conn.Log(logger.LevelWarn, "retention check failed, unable to cleanup folder %#v", folder.Path)
|
c.conn.Log(logger.LevelError, "retention check failed, unable to cleanup folder %#v", folder.Path)
|
||||||
c.sendNotifications(time.Since(startTime), err)
|
c.sendNotifications(time.Since(startTime), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -384,13 +384,13 @@ func (c *RetentionCheck) sendEmailNotification(elapsed time.Duration, errCheck e
|
||||||
data["Status"] = "Failed"
|
data["Status"] = "Failed"
|
||||||
}
|
}
|
||||||
if err := smtp.RenderRetentionReportTemplate(body, data); err != nil {
|
if err := smtp.RenderRetentionReportTemplate(body, data); err != nil {
|
||||||
c.conn.Log(logger.LevelWarn, "unable to render retention check template: %v", err)
|
c.conn.Log(logger.LevelError, "unable to render retention check template: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
subject := fmt.Sprintf("Retention check completed for user %#v", c.conn.User.Username)
|
subject := fmt.Sprintf("Retention check completed for user %#v", c.conn.User.Username)
|
||||||
if err := smtp.SendEmail(c.Email, subject, body.String(), smtp.EmailContentTypeTextHTML); err != nil {
|
if err := smtp.SendEmail(c.Email, subject, body.String(), smtp.EmailContentTypeTextHTML); err != nil {
|
||||||
c.conn.Log(logger.LevelWarn, "unable to notify retention check result via email: %v, elapsed: %v", err,
|
c.conn.Log(logger.LevelError, "unable to notify retention check result via email: %v, elapsed: %v", err,
|
||||||
time.Since(startTime))
|
time.Since(startTime))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,7 @@ func (c *RetentionCheck) sendHookNotification(elapsed time.Duration, errCheck er
|
||||||
var url *url.URL
|
var url *url.URL
|
||||||
url, err := url.Parse(Config.DataRetentionHook)
|
url, err := url.Parse(Config.DataRetentionHook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.conn.Log(logger.LevelWarn, "invalid data retention hook %#v: %v", Config.DataRetentionHook, err)
|
c.conn.Log(logger.LevelError, "invalid data retention hook %#v: %v", Config.DataRetentionHook, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
respCode := 0
|
respCode := 0
|
||||||
|
@ -447,7 +447,7 @@ func (c *RetentionCheck) sendHookNotification(elapsed time.Duration, errCheck er
|
||||||
}
|
}
|
||||||
if !filepath.IsAbs(Config.DataRetentionHook) {
|
if !filepath.IsAbs(Config.DataRetentionHook) {
|
||||||
err := fmt.Errorf("invalid data retention hook %#v", Config.DataRetentionHook)
|
err := fmt.Errorf("invalid data retention hook %#v", Config.DataRetentionHook)
|
||||||
c.conn.Log(logger.LevelWarn, "%v", err)
|
c.conn.Log(logger.LevelError, "%v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||||
|
|
|
@ -191,7 +191,7 @@ func (t *BaseTransfer) TransferError(err error) {
|
||||||
t.cancelFn()
|
t.cancelFn()
|
||||||
}
|
}
|
||||||
elapsed := time.Since(t.start).Nanoseconds() / 1000000
|
elapsed := time.Since(t.start).Nanoseconds() / 1000000
|
||||||
t.Connection.Log(logger.LevelWarn, "Unexpected error for transfer, path: %#v, error: \"%v\" bytes sent: %v, "+
|
t.Connection.Log(logger.LevelError, "Unexpected error for transfer, path: %#v, error: \"%v\" bytes sent: %v, "+
|
||||||
"bytes received: %v transfer running since %v ms", t.fsPath, t.ErrTransfer, atomic.LoadInt64(&t.BytesSent),
|
"bytes received: %v transfer running since %v ms", t.fsPath, t.ErrTransfer, atomic.LoadInt64(&t.BytesSent),
|
||||||
atomic.LoadInt64(&t.BytesReceived), elapsed)
|
atomic.LoadInt64(&t.BytesReceived), elapsed)
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ func (t *BaseTransfer) Close() error {
|
||||||
ExecuteActionNotification(t.Connection, operationUpload, t.fsPath, t.requestPath, "", "", "", fileSize, t.ErrTransfer)
|
ExecuteActionNotification(t.Connection, operationUpload, t.fsPath, t.requestPath, "", "", "", fileSize, t.ErrTransfer)
|
||||||
}
|
}
|
||||||
if t.ErrTransfer != nil {
|
if t.ErrTransfer != nil {
|
||||||
t.Connection.Log(logger.LevelWarn, "transfer error: %v, path: %#v", t.ErrTransfer, t.fsPath)
|
t.Connection.Log(logger.LevelError, "transfer error: %v, path: %#v", t.ErrTransfer, t.fsPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = t.ErrTransfer
|
err = t.ErrTransfer
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,14 +45,15 @@ func executeAction(operation, executor, ip, objectType, objectName string, objec
|
||||||
go func() {
|
go func() {
|
||||||
dataAsJSON, err := object.RenderAsJSON(operation != operationDelete)
|
dataAsJSON, err := object.RenderAsJSON(operation != operationDelete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to serialize user as JSON for operation %#v: %v", operation, err)
|
providerLog(logger.LevelError, "unable to serialize user as JSON for operation %#v: %v", operation, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(config.Actions.Hook, "http") {
|
if strings.HasPrefix(config.Actions.Hook, "http") {
|
||||||
var url *url.URL
|
var url *url.URL
|
||||||
url, err := url.Parse(config.Actions.Hook)
|
url, err := url.Parse(config.Actions.Hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "Invalid http_notification_url %#v for operation %#v: %v", config.Actions.Hook, operation, err)
|
providerLog(logger.LevelError, "Invalid http_notification_url %#v for operation %#v: %v",
|
||||||
|
config.Actions.Hook, operation, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
|
|
|
@ -303,7 +303,7 @@ func (a *Admin) RenderAsJSON(reload bool) ([]byte, error) {
|
||||||
if reload {
|
if reload {
|
||||||
admin, err := provider.adminExists(a.Username)
|
admin, err := provider.adminExists(a.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to reload admin before rendering as json: %v", err)
|
providerLog(logger.LevelError, "unable to reload admin before rendering as json: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
admin.HideConfidentialData()
|
admin.HideConfidentialData()
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (k *APIKey) RenderAsJSON(reload bool) ([]byte, error) {
|
||||||
if reload {
|
if reload {
|
||||||
apiKey, err := provider.apiKeyExists(k.KeyID)
|
apiKey, err := provider.apiKeyExists(k.KeyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to reload api key before rendering as json: %v", err)
|
providerLog(logger.LevelError, "unable to reload api key before rendering as json: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
apiKey.HideConfidentialData()
|
apiKey.HideConfidentialData()
|
||||||
|
|
|
@ -66,13 +66,13 @@ func initializeBoltProvider(basePath string) error {
|
||||||
_, e := tx.CreateBucketIfNotExists(bucket)
|
_, e := tx.CreateBucketIfNotExists(bucket)
|
||||||
return e
|
return e
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
providerLog(logger.LevelWarn, "error creating bucket %#v: %v", string(bucket), err)
|
providerLog(logger.LevelError, "error creating bucket %#v: %v", string(bucket), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provider = &BoltProvider{dbHandle: dbHandle}
|
provider = &BoltProvider{dbHandle: dbHandle}
|
||||||
} else {
|
} else {
|
||||||
providerLog(logger.LevelWarn, "error creating bolt key/value store handler: %v", err)
|
providerLog(logger.LevelError, "error creating bolt key/value store handler: %v", err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ func (p *BoltProvider) updateQuota(username string, filesAdd int, sizeAdd int64,
|
||||||
func (p *BoltProvider) getUsedQuota(username string) (int, int64, error) {
|
func (p *BoltProvider) getUsedQuota(username string) (int, int64, error) {
|
||||||
user, err := p.userExists(username)
|
user, err := p.userExists(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to get quota for user %v error: %v", username, err)
|
providerLog(logger.LevelError, "unable to get quota for user %v error: %v", username, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return user.UsedQuotaFiles, user.UsedQuotaSize, err
|
return user.UsedQuotaFiles, user.UsedQuotaSize, err
|
||||||
|
@ -923,7 +923,7 @@ func (p *BoltProvider) updateFolderQuota(name string, filesAdd int, sizeAdd int6
|
||||||
func (p *BoltProvider) getUsedFolderQuota(name string) (int, int64, error) {
|
func (p *BoltProvider) getUsedFolderQuota(name string) (int, int64, error) {
|
||||||
folder, err := p.getFolderByName(name)
|
folder, err := p.getFolderByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to get quota for folder %#v error: %v", name, err)
|
providerLog(logger.LevelError, "unable to get quota for folder %#v error: %v", name, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return folder.UsedQuotaFiles, folder.UsedQuotaSize, err
|
return folder.UsedQuotaFiles, folder.UsedQuotaSize, err
|
||||||
|
@ -1402,7 +1402,7 @@ func (p *BoltProvider) migrateDatabase() error {
|
||||||
return updateBoltDatabaseVersion(p.dbHandle, 14)
|
return updateBoltDatabaseVersion(p.dbHandle, 14)
|
||||||
default:
|
default:
|
||||||
if version > boltDatabaseVersion {
|
if version > boltDatabaseVersion {
|
||||||
providerLog(logger.LevelWarn, "database version %v is newer than the supported one: %v", version,
|
providerLog(logger.LevelError, "database version %v is newer than the supported one: %v", version,
|
||||||
boltDatabaseVersion)
|
boltDatabaseVersion)
|
||||||
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
||||||
boltDatabaseVersion)
|
boltDatabaseVersion)
|
||||||
|
|
|
@ -494,7 +494,7 @@ func Initialize(cnf Config, basePath string, checkAdmins bool) error {
|
||||||
err = provider.initializeDatabase()
|
err = provider.initializeDatabase()
|
||||||
if err != nil && err != ErrNoInitRequired {
|
if err != nil && err != ErrNoInitRequired {
|
||||||
logger.WarnToConsole("Unable to initialize data provider: %v", err)
|
logger.WarnToConsole("Unable to initialize data provider: %v", err)
|
||||||
providerLog(logger.LevelWarn, "Unable to initialize data provider: %v", err)
|
providerLog(logger.LevelError, "Unable to initialize data provider: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -502,13 +502,13 @@ func Initialize(cnf Config, basePath string, checkAdmins bool) error {
|
||||||
}
|
}
|
||||||
err = provider.migrateDatabase()
|
err = provider.migrateDatabase()
|
||||||
if err != nil && err != ErrNoInitRequired {
|
if err != nil && err != ErrNoInitRequired {
|
||||||
providerLog(logger.LevelWarn, "database migration error: %v", err)
|
providerLog(logger.LevelError, "database migration error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if checkAdmins && cnf.CreateDefaultAdmin {
|
if checkAdmins && cnf.CreateDefaultAdmin {
|
||||||
err = checkDefaultAdmin()
|
err = checkDefaultAdmin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "check default admin error: %v", err)
|
providerLog(logger.LevelError, "erro checking the default admin: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,7 +547,7 @@ func validateHooks() error {
|
||||||
}
|
}
|
||||||
_, err := os.Stat(hook)
|
_, err := os.Stat(hook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "invalid hook: %v", err)
|
providerLog(logger.LevelError, "invalid hook: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -568,7 +568,7 @@ func initializeHashingAlgo(cnf *Config) error {
|
||||||
if config.PasswordHashing.BcryptOptions.Cost > bcrypt.MaxCost {
|
if config.PasswordHashing.BcryptOptions.Cost > bcrypt.MaxCost {
|
||||||
err := fmt.Errorf("invalid bcrypt cost %v, max allowed %v", config.PasswordHashing.BcryptOptions.Cost, bcrypt.MaxCost)
|
err := fmt.Errorf("invalid bcrypt cost %v, max allowed %v", config.PasswordHashing.BcryptOptions.Cost, bcrypt.MaxCost)
|
||||||
logger.WarnToConsole("Unable to initialize data provider: %v", err)
|
logger.WarnToConsole("Unable to initialize data provider: %v", err)
|
||||||
providerLog(logger.LevelWarn, "Unable to initialize data provider: %v", err)
|
providerLog(logger.LevelError, "Unable to initialize data provider: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1878,7 +1878,7 @@ func isPasswordOK(user *User, password string) (bool, error) {
|
||||||
} else if strings.HasPrefix(user.Password, argonPwdPrefix) {
|
} else if strings.HasPrefix(user.Password, argonPwdPrefix) {
|
||||||
match, err = argon2id.ComparePasswordAndHash(password, user.Password)
|
match, err = argon2id.ComparePasswordAndHash(password, user.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error comparing password with argon hash: %v", err)
|
providerLog(logger.LevelError, "error comparing password with argon hash: %v", err)
|
||||||
return match, err
|
return match, err
|
||||||
}
|
}
|
||||||
} else if util.IsStringPrefixInSlice(user.Password, pbkdfPwdPrefixes) {
|
} else if util.IsStringPrefixInSlice(user.Password, pbkdfPwdPrefixes) {
|
||||||
|
@ -1975,7 +1975,7 @@ func checkUserPasscode(user *User, password, protocol string) (string, error) {
|
||||||
}
|
}
|
||||||
err := user.Filters.TOTPConfig.Secret.TryDecrypt()
|
err := user.Filters.TOTPConfig.Secret.TryDecrypt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
providerLog(logger.LevelError, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
||||||
user.Username, protocol, err)
|
user.Username, protocol, err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -2006,7 +2006,7 @@ func checkUserAndPubKey(user *User, pubKey []byte) (User, string, error) {
|
||||||
for i, k := range user.PublicKeys {
|
for i, k := range user.PublicKeys {
|
||||||
storedPubKey, comment, _, _, err := ssh.ParseAuthorizedKey([]byte(k))
|
storedPubKey, comment, _, _, err := ssh.ParseAuthorizedKey([]byte(k))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error parsing stored public key %d for user %v: %v", i, user.Username, err)
|
providerLog(logger.LevelError, "error parsing stored public key %d for user %v: %v", i, user.Username, err)
|
||||||
return *user, "", err
|
return *user, "", err
|
||||||
}
|
}
|
||||||
if bytes.Equal(storedPubKey.Marshal(), pubKey) {
|
if bytes.Equal(storedPubKey.Marshal(), pubKey) {
|
||||||
|
@ -2153,7 +2153,7 @@ func checkCacheUpdates() {
|
||||||
checkTime := util.GetTimeAsMsSinceEpoch(time.Now())
|
checkTime := util.GetTimeAsMsSinceEpoch(time.Now())
|
||||||
users, err := provider.getRecentlyUpdatedUsers(lastCachesUpdate)
|
users, err := provider.getRecentlyUpdatedUsers(lastCachesUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to get recently updated users: %v", err)
|
providerLog(logger.LevelError, "unable to get recently updated users: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
|
@ -2171,7 +2171,7 @@ func startUpdateCachesTimer() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !util.IsStringInSlice(config.Driver, sharedProviders) {
|
if !util.IsStringInSlice(config.Driver, sharedProviders) {
|
||||||
providerLog(logger.LevelWarn, "update caches not supported for provider %v", config.Driver)
|
providerLog(logger.LevelError, "update caches not supported for provider %v", config.Driver)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastCachesUpdate = util.GetTimeAsMsSinceEpoch(time.Now())
|
lastCachesUpdate = util.GetTimeAsMsSinceEpoch(time.Now())
|
||||||
|
@ -2210,7 +2210,7 @@ func startAvailabilityTimer() {
|
||||||
func checkDataprovider() {
|
func checkDataprovider() {
|
||||||
err := provider.checkAvailability()
|
err := provider.checkAvailability()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "check availability error: %v", err)
|
providerLog(logger.LevelError, "check availability error: %v", err)
|
||||||
}
|
}
|
||||||
metric.UpdateDataProviderAvailability(err)
|
metric.UpdateDataProviderAvailability(err)
|
||||||
}
|
}
|
||||||
|
@ -2229,12 +2229,12 @@ func terminateInteractiveAuthProgram(cmd *exec.Cmd, isFinished bool) {
|
||||||
func sendKeyboardAuthHTTPReq(url string, request *plugin.KeyboardAuthRequest) (*plugin.KeyboardAuthResponse, error) {
|
func sendKeyboardAuthHTTPReq(url string, request *plugin.KeyboardAuthRequest) (*plugin.KeyboardAuthResponse, error) {
|
||||||
reqAsJSON, err := json.Marshal(request)
|
reqAsJSON, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error serializing keyboard interactive auth request: %v", err)
|
providerLog(logger.LevelError, "error serializing keyboard interactive auth request: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp, err := httpclient.Post(url, "application/json", bytes.NewBuffer(reqAsJSON))
|
resp, err := httpclient.Post(url, "application/json", bytes.NewBuffer(reqAsJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error getting keyboard interactive auth hook HTTP response: %v", err)
|
providerLog(logger.LevelError, "error getting keyboard interactive auth hook HTTP response: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
@ -2263,7 +2263,7 @@ func doBuiltinKeyboardInteractiveAuth(user *User, client ssh.KeyboardInteractive
|
||||||
}
|
}
|
||||||
err = user.Filters.TOTPConfig.Secret.TryDecrypt()
|
err = user.Filters.TOTPConfig.Secret.TryDecrypt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
providerLog(logger.LevelError, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
||||||
user.Username, protocol, err)
|
user.Username, protocol, err)
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -2389,7 +2389,7 @@ func getKeyboardInteractiveAnswers(client ssh.KeyboardInteractiveChallenge, resp
|
||||||
}
|
}
|
||||||
err := user.Filters.TOTPConfig.Secret.TryDecrypt()
|
err := user.Filters.TOTPConfig.Secret.TryDecrypt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
providerLog(logger.LevelError, "unable to decrypt TOTP secret for user %#v, protocol %v, err: %v",
|
||||||
user.Username, protocol, err)
|
user.Username, protocol, err)
|
||||||
return answers, fmt.Errorf("unable to decrypt TOTP secret: %w", err)
|
return answers, fmt.Errorf("unable to decrypt TOTP secret: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -2554,7 +2554,7 @@ func getPasswordHookResponse(username, password, ip, protocol string) ([]byte, e
|
||||||
}
|
}
|
||||||
resp, err := httpclient.Post(config.CheckPasswordHook, "application/json", bytes.NewBuffer(reqAsJSON))
|
resp, err := httpclient.Post(config.CheckPasswordHook, "application/json", bytes.NewBuffer(reqAsJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error getting check password hook response: %v", err)
|
providerLog(logger.LevelError, "error getting check password hook response: %v", err)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
@ -2599,7 +2599,7 @@ func getPreLoginHookResponse(loginMethod, ip, protocol string, userAsJSON []byte
|
||||||
var result []byte
|
var result []byte
|
||||||
url, err := url.Parse(config.PreLoginHook)
|
url, err := url.Parse(config.PreLoginHook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "invalid url for pre-login hook %#v, error: %v", config.PreLoginHook, err)
|
providerLog(logger.LevelError, "invalid url for pre-login hook %#v, error: %v", config.PreLoginHook, err)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
|
@ -2723,7 +2723,7 @@ func ExecutePostLoginHook(user *User, loginMethod, ip, protocol string, err erro
|
||||||
user.PrepareForRendering()
|
user.PrepareForRendering()
|
||||||
userAsJSON, err := json.Marshal(user)
|
userAsJSON, err := json.Marshal(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error serializing user in post login hook: %v", err)
|
providerLog(logger.LevelError, "error serializing user in post login hook: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(config.PostLoginHook, "http") {
|
if strings.HasPrefix(config.PostLoginHook, "http") {
|
||||||
|
@ -2791,7 +2791,7 @@ func getExternalAuthResponse(username, password, pkey, keyboardInteractive, ip,
|
||||||
}
|
}
|
||||||
authRequestAsJSON, err := json.Marshal(authRequest)
|
authRequestAsJSON, err := json.Marshal(authRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error serializing external auth request: %v", err)
|
providerLog(logger.LevelError, "error serializing external auth request: %v", err)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
resp, err := httpclient.Post(config.ExternalAuthHook, "application/json", bytes.NewBuffer(authRequestAsJSON))
|
resp, err := httpclient.Post(config.ExternalAuthHook, "application/json", bytes.NewBuffer(authRequestAsJSON))
|
||||||
|
|
|
@ -216,7 +216,7 @@ func (p *MemoryProvider) updateQuota(username string, filesAdd int, sizeAdd int6
|
||||||
}
|
}
|
||||||
user, err := p.userExistsInternal(username)
|
user, err := p.userExistsInternal(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to update quota for user %#v error: %v", username, err)
|
providerLog(logger.LevelError, "unable to update quota for user %#v error: %v", username, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if reset {
|
if reset {
|
||||||
|
@ -241,7 +241,7 @@ func (p *MemoryProvider) getUsedQuota(username string) (int, int64, error) {
|
||||||
}
|
}
|
||||||
user, err := p.userExistsInternal(username)
|
user, err := p.userExistsInternal(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to get quota for user %#v error: %v", username, err)
|
providerLog(logger.LevelError, "unable to get quota for user %#v error: %v", username, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return user.UsedQuotaFiles, user.UsedQuotaSize, err
|
return user.UsedQuotaFiles, user.UsedQuotaSize, err
|
||||||
|
@ -590,7 +590,7 @@ func (p *MemoryProvider) updateFolderQuota(name string, filesAdd int, sizeAdd in
|
||||||
}
|
}
|
||||||
folder, err := p.folderExistsInternal(name)
|
folder, err := p.folderExistsInternal(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to update quota for folder %#v error: %v", name, err)
|
providerLog(logger.LevelError, "unable to update quota for folder %#v error: %v", name, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if reset {
|
if reset {
|
||||||
|
@ -613,7 +613,7 @@ func (p *MemoryProvider) getUsedFolderQuota(name string) (int, int64, error) {
|
||||||
}
|
}
|
||||||
folder, err := p.folderExistsInternal(name)
|
folder, err := p.folderExistsInternal(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to get quota for folder %#v error: %v", name, err)
|
providerLog(logger.LevelError, "unable to get quota for folder %#v error: %v", name, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return folder.UsedQuotaFiles, folder.UsedQuotaSize, err
|
return folder.UsedQuotaFiles, folder.UsedQuotaSize, err
|
||||||
|
@ -1309,27 +1309,27 @@ func (p *MemoryProvider) reloadConfig() error {
|
||||||
providerLog(logger.LevelDebug, "loading dump from file: %#v", p.dbHandle.configFile)
|
providerLog(logger.LevelDebug, "loading dump from file: %#v", p.dbHandle.configFile)
|
||||||
fi, err := os.Stat(p.dbHandle.configFile)
|
fi, err := os.Stat(p.dbHandle.configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error loading dump: %v", err)
|
providerLog(logger.LevelError, "error loading dump: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fi.Size() == 0 {
|
if fi.Size() == 0 {
|
||||||
err = errors.New("dump configuration file is invalid, its size must be > 0")
|
err = errors.New("dump configuration file is invalid, its size must be > 0")
|
||||||
providerLog(logger.LevelWarn, "error loading dump: %v", err)
|
providerLog(logger.LevelError, "error loading dump: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fi.Size() > 10485760 {
|
if fi.Size() > 10485760 {
|
||||||
err = errors.New("dump configuration file is invalid, its size must be <= 10485760 bytes")
|
err = errors.New("dump configuration file is invalid, its size must be <= 10485760 bytes")
|
||||||
providerLog(logger.LevelWarn, "error loading dump: %v", err)
|
providerLog(logger.LevelError, "error loading dump: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
content, err := os.ReadFile(p.dbHandle.configFile)
|
content, err := os.ReadFile(p.dbHandle.configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error loading dump: %v", err)
|
providerLog(logger.LevelError, "error loading dump: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dump, err := ParseDumpData(content)
|
dump, err := ParseDumpData(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error loading dump: %v", err)
|
providerLog(logger.LevelError, "error loading dump: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.clear()
|
p.clear()
|
||||||
|
@ -1367,13 +1367,13 @@ func (p *MemoryProvider) restoreShares(dump *BackupData) error {
|
||||||
share.ID = s.ID
|
share.ID = s.ID
|
||||||
err = UpdateShare(&share, ActionExecutorSystem, "")
|
err = UpdateShare(&share, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error updating share %#v: %v", share.ShareID, err)
|
providerLog(logger.LevelError, "error updating share %#v: %v", share.ShareID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = AddShare(&share, ActionExecutorSystem, "")
|
err = AddShare(&share, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error adding share %#v: %v", share.ShareID, err)
|
providerLog(logger.LevelError, "error adding share %#v: %v", share.ShareID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1392,13 +1392,13 @@ func (p *MemoryProvider) restoreAPIKeys(dump *BackupData) error {
|
||||||
apiKey.ID = k.ID
|
apiKey.ID = k.ID
|
||||||
err = UpdateAPIKey(&apiKey, ActionExecutorSystem, "")
|
err = UpdateAPIKey(&apiKey, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error updating API key %#v: %v", apiKey.KeyID, err)
|
providerLog(logger.LevelError, "error updating API key %#v: %v", apiKey.KeyID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = AddAPIKey(&apiKey, ActionExecutorSystem, "")
|
err = AddAPIKey(&apiKey, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error adding API key %#v: %v", apiKey.KeyID, err)
|
providerLog(logger.LevelError, "error adding API key %#v: %v", apiKey.KeyID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1414,13 +1414,13 @@ func (p *MemoryProvider) restoreAdmins(dump *BackupData) error {
|
||||||
admin.ID = a.ID
|
admin.ID = a.ID
|
||||||
err = UpdateAdmin(&admin, ActionExecutorSystem, "")
|
err = UpdateAdmin(&admin, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error updating admin %#v: %v", admin.Username, err)
|
providerLog(logger.LevelError, "error updating admin %#v: %v", admin.Username, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = AddAdmin(&admin, ActionExecutorSystem, "")
|
err = AddAdmin(&admin, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error adding admin %#v: %v", admin.Username, err)
|
providerLog(logger.LevelError, "error adding admin %#v: %v", admin.Username, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1436,14 +1436,14 @@ func (p *MemoryProvider) restoreFolders(dump *BackupData) error {
|
||||||
folder.ID = f.ID
|
folder.ID = f.ID
|
||||||
err = UpdateFolder(&folder, f.Users, ActionExecutorSystem, "")
|
err = UpdateFolder(&folder, f.Users, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error updating folder %#v: %v", folder.Name, err)
|
providerLog(logger.LevelError, "error updating folder %#v: %v", folder.Name, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
folder.Users = nil
|
folder.Users = nil
|
||||||
err = AddFolder(&folder)
|
err = AddFolder(&folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error adding folder %#v: %v", folder.Name, err)
|
providerLog(logger.LevelError, "error adding folder %#v: %v", folder.Name, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1459,13 +1459,13 @@ func (p *MemoryProvider) restoreUsers(dump *BackupData) error {
|
||||||
user.ID = u.ID
|
user.ID = u.ID
|
||||||
err = UpdateUser(&user, ActionExecutorSystem, "")
|
err = UpdateUser(&user, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error updating user %#v: %v", user.Username, err)
|
providerLog(logger.LevelError, "error updating user %#v: %v", user.Username, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = AddUser(&user, ActionExecutorSystem, "")
|
err = AddUser(&user, ActionExecutorSystem, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error adding user %#v: %v", user.Username, err)
|
providerLog(logger.LevelError, "error adding user %#v: %v", user.Username, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func initializeMySQLProvider() error {
|
||||||
dbHandle.SetConnMaxLifetime(240 * time.Second)
|
dbHandle.SetConnMaxLifetime(240 * time.Second)
|
||||||
provider = &MySQLProvider{dbHandle: dbHandle}
|
provider = &MySQLProvider{dbHandle: dbHandle}
|
||||||
} else {
|
} else {
|
||||||
providerLog(logger.LevelWarn, "error creating mysql database handler, connection string: %#v, error: %v",
|
providerLog(logger.LevelError, "error creating mysql database handler, connection string: %#v, error: %v",
|
||||||
getMySQLConnectionString(true), err)
|
getMySQLConnectionString(true), err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -364,7 +364,7 @@ func (p *MySQLProvider) migrateDatabase() error {
|
||||||
return updateMySQLDatabaseFromV13(p.dbHandle)
|
return updateMySQLDatabaseFromV13(p.dbHandle)
|
||||||
default:
|
default:
|
||||||
if version > sqlDatabaseVersion {
|
if version > sqlDatabaseVersion {
|
||||||
providerLog(logger.LevelWarn, "database version %v is newer than the supported one: %v", version,
|
providerLog(logger.LevelError, "database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
|
|
|
@ -123,7 +123,7 @@ func initializePGSQLProvider() error {
|
||||||
dbHandle.SetConnMaxLifetime(240 * time.Second)
|
dbHandle.SetConnMaxLifetime(240 * time.Second)
|
||||||
provider = &PGSQLProvider{dbHandle: dbHandle}
|
provider = &PGSQLProvider{dbHandle: dbHandle}
|
||||||
} else {
|
} else {
|
||||||
providerLog(logger.LevelWarn, "error creating postgres database handler, connection string: %#v, error: %v",
|
providerLog(logger.LevelError, "error creating postgres database handler, connection string: %#v, error: %v",
|
||||||
getPGSQLConnectionString(true), err)
|
getPGSQLConnectionString(true), err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -385,7 +385,7 @@ func (p *PGSQLProvider) migrateDatabase() error {
|
||||||
return updatePGSQLDatabaseFromV13(p.dbHandle)
|
return updatePGSQLDatabaseFromV13(p.dbHandle)
|
||||||
default:
|
default:
|
||||||
if version > sqlDatabaseVersion {
|
if version > sqlDatabaseVersion {
|
||||||
providerLog(logger.LevelWarn, "database version %v is newer than the supported one: %v", version,
|
providerLog(logger.LevelError, "database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
|
|
|
@ -137,7 +137,7 @@ func (s *Share) RenderAsJSON(reload bool) ([]byte, error) {
|
||||||
if reload {
|
if reload {
|
||||||
share, err := provider.shareExists(s.ShareID, s.Username)
|
share, err := provider.shareExists(s.ShareID, s.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to reload share before rendering as json: %v", err)
|
providerLog(logger.LevelError, "unable to reload share before rendering as json: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
share.HideConfidentialData()
|
share.HideConfidentialData()
|
||||||
|
|
|
@ -46,7 +46,7 @@ func sqlCommonGetShareByID(shareID, username string, dbHandle sqlQuerier) (Share
|
||||||
q := getShareByIDQuery(filterUser)
|
q := getShareByIDQuery(filterUser)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return share, err
|
return share, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -88,7 +88,7 @@ func sqlCommonAddShare(share *Share, dbHandle *sql.DB) error {
|
||||||
q := getAddShareQuery()
|
q := getAddShareQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -147,7 +147,7 @@ func sqlCommonUpdateShare(share *Share, dbHandle *sql.DB) error {
|
||||||
}
|
}
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -177,7 +177,7 @@ func sqlCommonDeleteShare(share *Share, dbHandle *sql.DB) error {
|
||||||
q := getDeleteShareQuery()
|
q := getDeleteShareQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -193,7 +193,7 @@ func sqlCommonGetShares(limit, offset int, order, username string, dbHandle sqlQ
|
||||||
q := getSharesQuery(order)
|
q := getSharesQuery(order)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -224,7 +224,7 @@ func sqlCommonDumpShares(dbHandle sqlQuerier) ([]Share, error) {
|
||||||
q := getDumpSharesQuery()
|
q := getDumpSharesQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -254,7 +254,7 @@ func sqlCommonGetAPIKeyByID(keyID string, dbHandle sqlQuerier) (APIKey, error) {
|
||||||
q := getAPIKeyByIDQuery()
|
q := getAPIKeyByIDQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return apiKey, err
|
return apiKey, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -283,7 +283,7 @@ func sqlCommonAddAPIKey(apiKey *APIKey, dbHandle *sql.DB) error {
|
||||||
q := getAddAPIKeyQuery()
|
q := getAddAPIKeyQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -310,7 +310,7 @@ func sqlCommonUpdateAPIKey(apiKey *APIKey, dbHandle *sql.DB) error {
|
||||||
q := getUpdateAPIKeyQuery()
|
q := getUpdateAPIKeyQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -326,7 +326,7 @@ func sqlCommonDeleteAPIKey(apiKey *APIKey, dbHandle *sql.DB) error {
|
||||||
q := getDeleteAPIKeyQuery()
|
q := getDeleteAPIKeyQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -342,7 +342,7 @@ func sqlCommonGetAPIKeys(limit, offset int, order string, dbHandle sqlQuerier) (
|
||||||
q := getAPIKeysQuery(order)
|
q := getAPIKeysQuery(order)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -381,7 +381,7 @@ func sqlCommonDumpAPIKeys(dbHandle sqlQuerier) ([]APIKey, error) {
|
||||||
q := getDumpAPIKeysQuery()
|
q := getDumpAPIKeysQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -418,7 +418,7 @@ func sqlCommonGetAdminByUsername(username string, dbHandle sqlQuerier) (Admin, e
|
||||||
q := getAdminByUsernameQuery()
|
q := getAdminByUsernameQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return admin, err
|
return admin, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -448,7 +448,7 @@ func sqlCommonAddAdmin(admin *Admin, dbHandle *sql.DB) error {
|
||||||
q := getAddAdminQuery()
|
q := getAddAdminQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -480,7 +480,7 @@ func sqlCommonUpdateAdmin(admin *Admin, dbHandle *sql.DB) error {
|
||||||
q := getUpdateAdminQuery()
|
q := getUpdateAdminQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -506,7 +506,7 @@ func sqlCommonDeleteAdmin(admin *Admin, dbHandle *sql.DB) error {
|
||||||
q := getDeleteAdminQuery()
|
q := getDeleteAdminQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -522,7 +522,7 @@ func sqlCommonGetAdmins(limit, offset int, order string, dbHandle sqlQuerier) ([
|
||||||
q := getAdminsQuery(order)
|
q := getAdminsQuery(order)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -553,7 +553,7 @@ func sqlCommonDumpAdmins(dbHandle sqlQuerier) ([]Admin, error) {
|
||||||
q := getDumpAdminsQuery()
|
q := getDumpAdminsQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -582,7 +582,7 @@ func sqlCommonGetUserByUsername(username string, dbHandle sqlQuerier) (User, err
|
||||||
q := getUserByUsernameQuery()
|
q := getUserByUsernameQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -646,7 +646,7 @@ func sqlCommonUpdateQuota(username string, filesAdd int, sizeAdd int64, reset bo
|
||||||
q := getUpdateQuotaQuery(reset)
|
q := getUpdateQuotaQuery(reset)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -655,7 +655,7 @@ func sqlCommonUpdateQuota(username string, filesAdd int, sizeAdd int64, reset bo
|
||||||
providerLog(logger.LevelDebug, "quota updated for user %#v, files increment: %v size increment: %v is reset? %v",
|
providerLog(logger.LevelDebug, "quota updated for user %#v, files increment: %v size increment: %v is reset? %v",
|
||||||
username, filesAdd, sizeAdd, reset)
|
username, filesAdd, sizeAdd, reset)
|
||||||
} else {
|
} else {
|
||||||
providerLog(logger.LevelWarn, "error updating quota for user %#v: %v", username, err)
|
providerLog(logger.LevelError, "error updating quota for user %#v: %v", username, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ func sqlCommonGetUsedQuota(username string, dbHandle *sql.DB) (int, int64, error
|
||||||
q := getQuotaQuery()
|
q := getQuotaQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -675,7 +675,7 @@ func sqlCommonGetUsedQuota(username string, dbHandle *sql.DB) (int, int64, error
|
||||||
var usedSize int64
|
var usedSize int64
|
||||||
err = stmt.QueryRowContext(ctx, username).Scan(&usedSize, &usedFiles)
|
err = stmt.QueryRowContext(ctx, username).Scan(&usedSize, &usedFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error getting quota for user: %v, error: %v", username, err)
|
providerLog(logger.LevelError, "error getting quota for user: %v, error: %v", username, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return usedFiles, usedSize, err
|
return usedFiles, usedSize, err
|
||||||
|
@ -687,7 +687,7 @@ func sqlCommonUpdateShareLastUse(shareID string, numTokens int, dbHandle *sql.DB
|
||||||
q := getUpdateShareLastUseQuery()
|
q := getUpdateShareLastUseQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -706,7 +706,7 @@ func sqlCommonUpdateAPIKeyLastUse(keyID string, dbHandle *sql.DB) error {
|
||||||
q := getUpdateAPIKeyLastUseQuery()
|
q := getUpdateAPIKeyLastUseQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -725,7 +725,7 @@ func sqlCommonUpdateAdminLastLogin(username string, dbHandle *sql.DB) error {
|
||||||
q := getUpdateAdminLastLoginQuery()
|
q := getUpdateAdminLastLoginQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -744,7 +744,7 @@ func sqlCommonSetUpdatedAt(username string, dbHandle *sql.DB) {
|
||||||
q := getSetUpdateAtQuery()
|
q := getSetUpdateAtQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -762,7 +762,7 @@ func sqlCommonUpdateLastLogin(username string, dbHandle *sql.DB) error {
|
||||||
q := getUpdateLastLoginQuery()
|
q := getUpdateLastLoginQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -787,7 +787,7 @@ func sqlCommonAddUser(user *User, dbHandle *sql.DB) error {
|
||||||
q := getAddUserQuery()
|
q := getAddUserQuery()
|
||||||
stmt, err := tx.PrepareContext(ctx, q)
|
stmt, err := tx.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -830,7 +830,7 @@ func sqlCommonUpdateUser(user *User, dbHandle *sql.DB) error {
|
||||||
q := getUpdateUserQuery()
|
q := getUpdateUserQuery()
|
||||||
stmt, err := tx.PrepareContext(ctx, q)
|
stmt, err := tx.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -867,7 +867,7 @@ func sqlCommonDeleteUser(user *User, dbHandle *sql.DB) error {
|
||||||
q := getDeleteUserQuery()
|
q := getDeleteUserQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -882,7 +882,7 @@ func sqlCommonDumpUsers(dbHandle sqlQuerier) ([]User, error) {
|
||||||
q := getDumpUsersQuery()
|
q := getDumpUsersQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -917,7 +917,7 @@ func sqlCommonGetRecentlyUpdatedUsers(after int64, dbHandle sqlQuerier) ([]User,
|
||||||
q := getRecentlyUpdatedUsersQuery()
|
q := getRecentlyUpdatedUsersQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -947,7 +947,7 @@ func sqlCommonGetUsers(limit int, offset int, order string, dbHandle sqlQuerier)
|
||||||
q := getUsersQuery(order)
|
q := getUsersQuery(order)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1119,7 +1119,7 @@ func getUserFromDbRow(row sqlScanner) (User, error) {
|
||||||
perms := make(map[string][]string)
|
perms := make(map[string][]string)
|
||||||
err = json.Unmarshal([]byte(permissions.String), &perms)
|
err = json.Unmarshal([]byte(permissions.String), &perms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to deserialize permissions for user %#v: %v", user.Username, err)
|
providerLog(logger.LevelError, "unable to deserialize permissions for user %#v: %v", user.Username, err)
|
||||||
return user, fmt.Errorf("unable to deserialize permissions for user %#v: %v", user.Username, err)
|
return user, fmt.Errorf("unable to deserialize permissions for user %#v: %v", user.Username, err)
|
||||||
}
|
}
|
||||||
user.Permissions = perms
|
user.Permissions = perms
|
||||||
|
@ -1156,7 +1156,7 @@ func sqlCommonCheckFolderExists(ctx context.Context, name string, dbHandle sqlQu
|
||||||
q := checkFolderNameQuery()
|
q := checkFolderNameQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1169,7 +1169,7 @@ func sqlCommonGetFolder(ctx context.Context, name string, dbHandle sqlQuerier) (
|
||||||
q := getFolderByNameQuery()
|
q := getFolderByNameQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return folder, err
|
return folder, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1254,7 +1254,7 @@ func sqlCommonAddFolder(folder *vfs.BaseVirtualFolder, dbHandle sqlQuerier) erro
|
||||||
q := getAddFolderQuery()
|
q := getAddFolderQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1277,7 +1277,7 @@ func sqlCommonUpdateFolder(folder *vfs.BaseVirtualFolder, dbHandle sqlQuerier) e
|
||||||
q := getUpdateFolderQuery()
|
q := getUpdateFolderQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1291,7 +1291,7 @@ func sqlCommonDeleteFolder(folder *vfs.BaseVirtualFolder, dbHandle sqlQuerier) e
|
||||||
q := getDeleteFolderQuery()
|
q := getDeleteFolderQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1306,7 +1306,7 @@ func sqlCommonDumpFolders(dbHandle sqlQuerier) ([]vfs.BaseVirtualFolder, error)
|
||||||
q := getDumpFoldersQuery()
|
q := getDumpFoldersQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1352,7 +1352,7 @@ func sqlCommonGetFolders(limit, offset int, order string, dbHandle sqlQuerier) (
|
||||||
q := getFoldersQuery(order)
|
q := getFoldersQuery(order)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1398,7 +1398,7 @@ func sqlCommonClearFolderMapping(ctx context.Context, user *User, dbHandle sqlQu
|
||||||
q := getClearFolderMappingQuery()
|
q := getClearFolderMappingQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1410,7 +1410,7 @@ func sqlCommonAddFolderMapping(ctx context.Context, user *User, folder *vfs.Virt
|
||||||
q := getAddFolderMappingQuery()
|
q := getAddFolderMappingQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1459,7 +1459,7 @@ func getUsersWithVirtualFolders(ctx context.Context, users []User, dbHandle sqlQ
|
||||||
q := getRelatedFoldersForUsersQuery(users)
|
q := getRelatedFoldersForUsersQuery(users)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1519,7 +1519,7 @@ func getVirtualFoldersWithUsers(folders []vfs.BaseVirtualFolder, dbHandle sqlQue
|
||||||
q := getRelatedUsersForFoldersQuery(folders)
|
q := getRelatedUsersForFoldersQuery(folders)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1557,7 +1557,7 @@ func sqlCommonUpdateFolderQuota(name string, filesAdd int, sizeAdd int64, reset
|
||||||
q := getUpdateFolderQuotaQuery(reset)
|
q := getUpdateFolderQuotaQuery(reset)
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1577,7 +1577,7 @@ func sqlCommonGetFolderUsedQuota(mappedPath string, dbHandle *sql.DB) (int, int6
|
||||||
q := getQuotaFolderQuery()
|
q := getQuotaFolderQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1586,7 +1586,7 @@ func sqlCommonGetFolderUsedQuota(mappedPath string, dbHandle *sql.DB) (int, int6
|
||||||
var usedSize int64
|
var usedSize int64
|
||||||
err = stmt.QueryRowContext(ctx, mappedPath).Scan(&usedSize, &usedFiles)
|
err = stmt.QueryRowContext(ctx, mappedPath).Scan(&usedSize, &usedFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error getting quota for folder: %v, error: %v", mappedPath, err)
|
providerLog(logger.LevelError, "error getting quota for folder: %v, error: %v", mappedPath, err)
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
return usedFiles, usedSize, err
|
return usedFiles, usedSize, err
|
||||||
|
@ -1623,7 +1623,7 @@ func getRelatedValuesForAPIKeys(ctx context.Context, apiKeys []APIKey, dbHandle
|
||||||
}
|
}
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
@ -1687,7 +1687,7 @@ func sqlCommonGetDatabaseVersion(dbHandle *sql.DB, showInitWarn bool) (schemaVer
|
||||||
q := getDatabaseVersionQuery()
|
q := getDatabaseVersionQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
if showInitWarn && strings.Contains(err.Error(), sqlTableSchemaVersion) {
|
if showInitWarn && strings.Contains(err.Error(), sqlTableSchemaVersion) {
|
||||||
logger.WarnToConsole("database query error, did you forgot to run the \"initprovider\" command?")
|
logger.WarnToConsole("database query error, did you forgot to run the \"initprovider\" command?")
|
||||||
}
|
}
|
||||||
|
@ -1703,7 +1703,7 @@ func sqlCommonUpdateDatabaseVersion(ctx context.Context, dbHandle sqlQuerier, ve
|
||||||
q := getUpdateDBVersionQuery()
|
q := getUpdateDBVersionQuery()
|
||||||
stmt, err := dbHandle.PrepareContext(ctx, q)
|
stmt, err := dbHandle.PrepareContext(ctx, q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "error preparing database query %#v: %v", q, err)
|
providerLog(logger.LevelError, "error preparing database query %#v: %v", q, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
|
|
@ -119,7 +119,7 @@ func initializeSQLiteProvider(basePath string) error {
|
||||||
dbHandle.SetMaxOpenConns(1)
|
dbHandle.SetMaxOpenConns(1)
|
||||||
provider = &SQLiteProvider{dbHandle: dbHandle}
|
provider = &SQLiteProvider{dbHandle: dbHandle}
|
||||||
} else {
|
} else {
|
||||||
providerLog(logger.LevelWarn, "error creating sqlite database handler, connection string: %#v, error: %v",
|
providerLog(logger.LevelError, "error creating sqlite database handler, connection string: %#v, error: %v",
|
||||||
connectionString, err)
|
connectionString, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -361,7 +361,7 @@ func (p *SQLiteProvider) migrateDatabase() error {
|
||||||
return updateSQLiteDatabaseFromV13(p.dbHandle)
|
return updateSQLiteDatabaseFromV13(p.dbHandle)
|
||||||
default:
|
default:
|
||||||
if version > sqlDatabaseVersion {
|
if version > sqlDatabaseVersion {
|
||||||
providerLog(logger.LevelWarn, "database version %v is newer than the supported one: %v", version,
|
providerLog(logger.LevelError, "database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
logger.WarnToConsole("database version %v is newer than the supported one: %v", version,
|
||||||
sqlDatabaseVersion)
|
sqlDatabaseVersion)
|
||||||
|
|
|
@ -238,7 +238,7 @@ func (u *User) RenderAsJSON(reload bool) ([]byte, error) {
|
||||||
if reload {
|
if reload {
|
||||||
user, err := provider.userExists(u.Username)
|
user, err := provider.userExists(u.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
providerLog(logger.LevelWarn, "unable to reload user before rendering as json: %v", err)
|
providerLog(logger.LevelError, "unable to reload user before rendering as json: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
user.PrepareForRendering()
|
user.PrepareForRendering()
|
||||||
|
|
|
@ -113,12 +113,12 @@ func (c *Connection) Remove(name string) error {
|
||||||
|
|
||||||
var fi os.FileInfo
|
var fi os.FileInfo
|
||||||
if fi, err = fs.Lstat(p); err != nil {
|
if fi, err = fs.Lstat(p); err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to remove file %#v: stat error: %+v", p, err)
|
c.Log(logger.LevelError, "failed to remove file %#v: stat error: %+v", p, err)
|
||||||
return c.GetFsError(fs, err)
|
return c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.IsDir() && fi.Mode()&os.ModeSymlink == 0 {
|
if fi.IsDir() && fi.Mode()&os.ModeSymlink == 0 {
|
||||||
c.Log(logger.LevelDebug, "cannot remove %#v is not a file/symlink", p)
|
c.Log(logger.LevelError, "cannot remove %#v is not a file/symlink", p)
|
||||||
return c.GetGenericError(nil)
|
return c.GetGenericError(nil)
|
||||||
}
|
}
|
||||||
return c.RemoveFile(fs, p, name, fi)
|
return c.RemoveFile(fs, p, name, fi)
|
||||||
|
@ -332,7 +332,7 @@ func (c *Connection) downloadFile(fs vfs.Fs, fsPath, ftpPath string, offset int6
|
||||||
|
|
||||||
file, r, cancelFn, err := fs.Open(fsPath, offset)
|
file, r, cancelFn, err := fs.Open(fsPath, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "could not open file %#v for reading: %+v", fsPath, err)
|
c.Log(logger.LevelError, "could not open file %#v for reading: %+v", fsPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ func (c *Connection) uploadFile(fs vfs.Fs, fsPath, ftpPath string, flags int) (f
|
||||||
|
|
||||||
// This happen if we upload a file that has the same name of an existing directory
|
// This happen if we upload a file that has the same name of an existing directory
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
c.Log(logger.LevelWarn, "attempted to open a directory for writing to: %#v", fsPath)
|
c.Log(logger.LevelError, "attempted to open a directory for writing to: %#v", fsPath)
|
||||||
return nil, c.GetOpUnsupportedError()
|
return nil, c.GetOpUnsupportedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ func (c *Connection) handleFTPUploadToNewFile(fs vfs.Fs, resolvedPath, filePath,
|
||||||
}
|
}
|
||||||
file, w, cancelFn, err := fs.Create(filePath, 0)
|
file, w, cancelFn, err := fs.Create(filePath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error creating file %#v: %+v", resolvedPath, err)
|
c.Log(logger.LevelError, "error creating file %#v: %+v", resolvedPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ func (c *Connection) handleFTPUploadToExistingFile(fs vfs.Fs, flags int, resolve
|
||||||
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
||||||
err = fs.Rename(resolvedPath, filePath)
|
err = fs.Rename(resolvedPath, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
c.Log(logger.LevelError, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
||||||
resolvedPath, filePath, err)
|
resolvedPath, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ func (c *Connection) handleFTPUploadToExistingFile(fs vfs.Fs, flags int, resolve
|
||||||
|
|
||||||
file, w, cancelFn, err := fs.Create(filePath, flags)
|
file, w, cancelFn, err := fs.Create(filePath, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error opening existing file, flags: %v, source: %#v, err: %+v", flags, filePath, err)
|
c.Log(logger.LevelError, "error opening existing file, flags: %v, source: %#v, err: %+v", flags, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ func deleteUserFile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var fi os.FileInfo
|
var fi os.FileInfo
|
||||||
if fi, err = fs.Lstat(p); err != nil {
|
if fi, err = fs.Lstat(p); err != nil {
|
||||||
connection.Log(logger.LevelWarn, "failed to remove file %#v: stat error: %+v", p, err)
|
connection.Log(logger.LevelError, "failed to remove file %#v: stat error: %+v", p, err)
|
||||||
err = connection.GetFsError(fs, err)
|
err = connection.GetFsError(fs, err)
|
||||||
sendAPIResponse(w, r, err, fmt.Sprintf("Unable to delete file %#v", name), getMappedStatusCode(err))
|
sendAPIResponse(w, r, err, fmt.Sprintf("Unable to delete file %#v", name), getMappedStatusCode(err))
|
||||||
return
|
return
|
||||||
|
|
|
@ -198,7 +198,7 @@ func renderCompressedFiles(w http.ResponseWriter, conn *Connection, baseDir stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := wr.Close(); err != nil {
|
if err := wr.Close(); err != nil {
|
||||||
conn.Log(logger.LevelWarn, "unable to close zip file: %v", err)
|
conn.Log(logger.LevelError, "unable to close zip file: %v", err)
|
||||||
if share != nil {
|
if share != nil {
|
||||||
dataprovider.UpdateShareLastUse(share, -1) //nolint:errcheck
|
dataprovider.UpdateShareLastUse(share, -1) //nolint:errcheck
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func (c *Connection) getFileReader(name string, offset int64, method string) (io
|
||||||
|
|
||||||
file, r, cancelFn, err := fs.Open(p, offset)
|
file, r, cancelFn, err := fs.Open(p, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "could not open file %#v for reading: %+v", p, err)
|
c.Log(logger.LevelError, "could not open file %#v for reading: %+v", p, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func (c *Connection) getFileWriter(name string) (io.WriteCloser, error) {
|
||||||
|
|
||||||
// This happen if we upload a file that has the same name of an existing directory
|
// This happen if we upload a file that has the same name of an existing directory
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
c.Log(logger.LevelWarn, "attempted to open a directory for writing to: %#v", p)
|
c.Log(logger.LevelError, "attempted to open a directory for writing to: %#v", p)
|
||||||
return nil, c.GetOpUnsupportedError()
|
return nil, c.GetOpUnsupportedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ func (c *Connection) getFileWriter(name string) (io.WriteCloser, error) {
|
||||||
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
||||||
err = fs.Rename(p, filePath)
|
err = fs.Rename(p, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
c.Log(logger.LevelError, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
||||||
p, filePath, err)
|
p, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ func (c *Connection) handleUploadFile(fs vfs.Fs, resolvedPath, filePath, request
|
||||||
|
|
||||||
file, w, cancelFn, err := fs.Create(filePath, 0)
|
file, w, cancelFn, err := fs.Create(filePath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error opening existing file, source: %#v, err: %+v", filePath, err)
|
c.Log(logger.LevelError, "error opening existing file, source: %#v, err: %+v", filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (c *Connection) Fileread(request *sftp.Request) (io.ReaderAt, error) {
|
||||||
|
|
||||||
file, r, cancelFn, err := fs.Open(p, 0)
|
file, r, cancelFn, err := fs.Open(p, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "could not open file %#v for reading: %+v", p, err)
|
c.Log(logger.LevelError, "could not open file %#v for reading: %+v", p, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func (c *Connection) handleFilewrite(request *sftp.Request) (sftp.WriterAtReader
|
||||||
|
|
||||||
// This happen if we upload a file that has the same name of an existing directory
|
// This happen if we upload a file that has the same name of an existing directory
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
c.Log(logger.LevelWarn, "attempted to open a directory for writing to: %#v", p)
|
c.Log(logger.LevelError, "attempted to open a directory for writing to: %#v", p)
|
||||||
return nil, sftp.ErrSSHFxOpUnsupported
|
return nil, sftp.ErrSSHFxOpUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +356,7 @@ func (c *Connection) handleSFTPUploadToNewFile(fs vfs.Fs, resolvedPath, filePath
|
||||||
|
|
||||||
file, w, cancelFn, err := fs.Create(filePath, 0)
|
file, w, cancelFn, err := fs.Create(filePath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error creating file %#v: %+v", resolvedPath, err)
|
c.Log(logger.LevelError, "error creating file %#v: %+v", resolvedPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,7 +404,7 @@ func (c *Connection) handleSFTPUploadToExistingFile(fs vfs.Fs, pflags sftp.FileO
|
||||||
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
||||||
err = fs.Rename(resolvedPath, filePath)
|
err = fs.Rename(resolvedPath, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
c.Log(logger.LevelError, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
||||||
resolvedPath, filePath, err)
|
resolvedPath, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ func (c *Connection) handleSFTPUploadToExistingFile(fs vfs.Fs, pflags sftp.FileO
|
||||||
|
|
||||||
file, w, cancelFn, err := fs.Create(filePath, osFlags)
|
file, w, cancelFn, err := fs.Create(filePath, osFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error opening existing file, flags: %v, source: %#v, err: %+v", pflags, filePath, err)
|
c.Log(logger.LevelError, "error opening existing file, flags: %v, source: %#v, err: %+v", pflags, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
sftpd/scp.go
30
sftpd/scp.go
|
@ -78,7 +78,7 @@ func (c *scpCommand) handleRecursiveUpload() error {
|
||||||
for {
|
for {
|
||||||
fs, err := c.connection.User.GetFilesystemForPath(destPath, c.connection.ID)
|
fs, err := c.connection.User.GetFilesystemForPath(destPath, c.connection.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error uploading file %#v: %+v", destPath, err)
|
c.connection.Log(logger.LevelError, "error uploading file %#v: %+v", destPath, err)
|
||||||
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", destPath))
|
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", destPath))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ func (c *scpCommand) handleRecursiveUpload() error {
|
||||||
destPath = path.Join(destPath, name)
|
destPath = path.Join(destPath, name)
|
||||||
fs, err = c.connection.User.GetFilesystemForPath(destPath, c.connection.ID)
|
fs, err = c.connection.User.GetFilesystemForPath(destPath, c.connection.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error uploading file %#v: %+v", destPath, err)
|
c.connection.Log(logger.LevelError, "error uploading file %#v: %+v", destPath, err)
|
||||||
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", destPath))
|
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", destPath))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -138,12 +138,12 @@ func (c *scpCommand) handleCreateDir(fs vfs.Fs, dirPath string) error {
|
||||||
|
|
||||||
p, err := fs.ResolvePath(dirPath)
|
p, err := fs.ResolvePath(dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error creating dir: %#v, invalid file path, err: %v", dirPath, err)
|
c.connection.Log(logger.LevelError, "error creating dir: %#v, invalid file path, err: %v", dirPath, err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !c.connection.User.HasPerm(dataprovider.PermCreateDirs, path.Dir(dirPath)) {
|
if !c.connection.User.HasPerm(dataprovider.PermCreateDirs, path.Dir(dirPath)) {
|
||||||
c.connection.Log(logger.LevelWarn, "error creating dir: %#v, permission denied", dirPath)
|
c.connection.Log(logger.LevelError, "error creating dir: %#v, permission denied", dirPath)
|
||||||
c.sendErrorMessage(fs, common.ErrPermissionDenied)
|
c.sendErrorMessage(fs, common.ErrPermissionDenied)
|
||||||
return common.ErrPermissionDenied
|
return common.ErrPermissionDenied
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ func (c *scpCommand) handleUploadFile(fs vfs.Fs, resolvedPath, filePath string,
|
||||||
quotaResult := c.connection.HasSpace(isNewFile, false, requestPath)
|
quotaResult := c.connection.HasSpace(isNewFile, false, requestPath)
|
||||||
if !quotaResult.HasSpace {
|
if !quotaResult.HasSpace {
|
||||||
err := fmt.Errorf("denying file write due to quota limits")
|
err := fmt.Errorf("denying file write due to quota limits")
|
||||||
c.connection.Log(logger.LevelWarn, "error uploading file: %#v, err: %v", filePath, err)
|
c.connection.Log(logger.LevelError, "error uploading file: %#v, err: %v", filePath, err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ func (c *scpCommand) handleUpload(uploadFilePath string, sizeToRead int64) error
|
||||||
|
|
||||||
fs, p, err := c.connection.GetFsAndResolvedPath(uploadFilePath)
|
fs, p, err := c.connection.GetFsAndResolvedPath(uploadFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error uploading file: %#v, err: %v", uploadFilePath, err)
|
c.connection.Log(logger.LevelError, "error uploading file: %#v, err: %v", uploadFilePath, err)
|
||||||
c.sendErrorMessage(nil, err)
|
c.sendErrorMessage(nil, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ func (c *scpCommand) handleUpload(uploadFilePath string, sizeToRead int64) error
|
||||||
}
|
}
|
||||||
|
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
c.connection.Log(logger.LevelWarn, "attempted to open a directory for writing to: %#v", p)
|
c.connection.Log(logger.LevelError, "attempted to open a directory for writing to: %#v", p)
|
||||||
err = fmt.Errorf("attempted to open a directory for writing: %#v", p)
|
err = fmt.Errorf("attempted to open a directory for writing: %#v", p)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return err
|
return err
|
||||||
|
@ -473,7 +473,7 @@ func (c *scpCommand) handleDownload(filePath string) error {
|
||||||
|
|
||||||
fs, err := c.connection.User.GetFilesystemForPath(filePath, c.connection.ID)
|
fs, err := c.connection.User.GetFilesystemForPath(filePath, c.connection.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error downloading file %#v: %+v", filePath, err)
|
c.connection.Log(logger.LevelError, "error downloading file %#v: %+v", filePath, err)
|
||||||
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", filePath))
|
c.sendErrorMessage(nil, fmt.Errorf("unable to get fs for path %#v", filePath))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -481,14 +481,14 @@ func (c *scpCommand) handleDownload(filePath string) error {
|
||||||
p, err := fs.ResolvePath(filePath)
|
p, err := fs.ResolvePath(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("invalid file path %#v", filePath)
|
err := fmt.Errorf("invalid file path %#v", filePath)
|
||||||
c.connection.Log(logger.LevelWarn, "error downloading file: %#v, invalid file path", filePath)
|
c.connection.Log(logger.LevelError, "error downloading file: %#v, invalid file path", filePath)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var stat os.FileInfo
|
var stat os.FileInfo
|
||||||
if stat, err = fs.Stat(p); err != nil {
|
if stat, err = fs.Stat(p); err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error downloading file: %#v->%#v, err: %v", filePath, p, err)
|
c.connection.Log(logger.LevelError, "error downloading file: %#v->%#v, err: %v", filePath, p, err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -636,7 +636,7 @@ func (c *scpCommand) sendConfirmationMessage() error {
|
||||||
func (c *scpCommand) sendProtocolMessage(message string) error {
|
func (c *scpCommand) sendProtocolMessage(message string) error {
|
||||||
_, err := c.connection.channel.Write([]byte(message))
|
_, err := c.connection.channel.Write([]byte(message))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error sending protocol message: %v, err: %v", message, err)
|
c.connection.Log(logger.LevelError, "error sending protocol message: %v, err: %v", message, err)
|
||||||
c.connection.channel.Close()
|
c.connection.channel.Close()
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -686,7 +686,7 @@ func (c *scpCommand) parseUploadMessage(fs vfs.Fs, command string) (int64, strin
|
||||||
if !strings.HasPrefix(command, "C") && !strings.HasPrefix(command, "D") {
|
if !strings.HasPrefix(command, "C") && !strings.HasPrefix(command, "D") {
|
||||||
err = fmt.Errorf("unknown or invalid upload message: %v args: %v user: %v",
|
err = fmt.Errorf("unknown or invalid upload message: %v args: %v user: %v",
|
||||||
command, c.args, c.connection.User.Username)
|
command, c.args, c.connection.User.Username)
|
||||||
c.connection.Log(logger.LevelWarn, "error: %v", err)
|
c.connection.Log(logger.LevelError, "error: %v", err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return size, name, err
|
return size, name, err
|
||||||
}
|
}
|
||||||
|
@ -694,20 +694,20 @@ func (c *scpCommand) parseUploadMessage(fs vfs.Fs, command string) (int64, strin
|
||||||
if len(parts) == 3 {
|
if len(parts) == 3 {
|
||||||
size, err = strconv.ParseInt(parts[1], 10, 64)
|
size, err = strconv.ParseInt(parts[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.connection.Log(logger.LevelWarn, "error getting size from upload message: %v", err)
|
c.connection.Log(logger.LevelError, "error getting size from upload message: %v", err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return size, name, err
|
return size, name, err
|
||||||
}
|
}
|
||||||
name = parts[2]
|
name = parts[2]
|
||||||
if name == "" {
|
if name == "" {
|
||||||
err = fmt.Errorf("error getting name from upload message, cannot be empty")
|
err = fmt.Errorf("error getting name from upload message, cannot be empty")
|
||||||
c.connection.Log(logger.LevelWarn, "error: %v", err)
|
c.connection.Log(logger.LevelError, "error: %v", err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return size, name, err
|
return size, name, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("unable to split upload message: %#v", command)
|
err = fmt.Errorf("unable to split upload message: %#v", command)
|
||||||
c.connection.Log(logger.LevelWarn, "error: %v", err)
|
c.connection.Log(logger.LevelError, "error: %v", err)
|
||||||
c.sendErrorMessage(fs, err)
|
c.sendErrorMessage(fs, err)
|
||||||
return size, name, err
|
return size, name, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,7 +498,7 @@ func (c *Configuration) handleSftpConnection(channel ssh.Channel, connection *Co
|
||||||
_, err = channel.SendRequest("exit-status", false, ssh.Marshal(&exitStatus))
|
_, err = channel.SendRequest("exit-status", false, ssh.Marshal(&exitStatus))
|
||||||
connection.Log(logger.LevelInfo, "connection closed, sent exit status %+v error: %v", exitStatus, err)
|
connection.Log(logger.LevelInfo, "connection closed, sent exit status %+v error: %v", exitStatus, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
connection.Log(logger.LevelWarn, "connection closed with error: %v", err)
|
connection.Log(logger.LevelError, "connection closed with error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ func processSSHCommand(payload []byte, connection *Connection, enabledSSHCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := connection.CloseFS()
|
err := connection.CloseFS()
|
||||||
connection.Log(logger.LevelWarn, "unable to unmarshal ssh command, close fs, err: %v", err)
|
connection.Log(logger.LevelError, "unable to unmarshal ssh command, close fs, err: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,7 +727,7 @@ func (c *sshCommand) sendExitStatus(err error) {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status = uint32(1)
|
status = uint32(1)
|
||||||
c.connection.Log(logger.LevelWarn, "command failed: %#v args: %v user: %v err: %v",
|
c.connection.Log(logger.LevelError, "command failed: %#v args: %v user: %v err: %v",
|
||||||
c.command, c.args, c.connection.User.Username, err)
|
c.command, c.args, c.connection.User.Username, err)
|
||||||
}
|
}
|
||||||
exitStatus := sshSubsystemExitStatus{
|
exitStatus := sshSubsystemExitStatus{
|
||||||
|
|
14
vfs/osfs.go
14
vfs/osfs.go
|
@ -102,7 +102,7 @@ func (*OsFs) Create(name string, flag int) (File, *PipeWriter, func(), error) {
|
||||||
func (fs *OsFs) Rename(source, target string) error {
|
func (fs *OsFs) Rename(source, target string) error {
|
||||||
err := os.Rename(source, target)
|
err := os.Rename(source, target)
|
||||||
if err != nil && isCrossDeviceError(err) {
|
if err != nil && isCrossDeviceError(err) {
|
||||||
fsLog(fs, logger.LevelWarn, "cross device error detected while renaming %#v -> %#v. Trying a copy and remove, this could take a long time",
|
fsLog(fs, logger.LevelError, "cross device error detected while renaming %#v -> %#v. Trying a copy and remove, this could take a long time",
|
||||||
source, target)
|
source, target)
|
||||||
err = fscopy.Copy(source, target, fscopy.Options{
|
err = fscopy.Copy(source, target, fscopy.Options{
|
||||||
OnSymlink: func(src string) fscopy.SymlinkAction {
|
OnSymlink: func(src string) fscopy.SymlinkAction {
|
||||||
|
@ -110,7 +110,7 @@ func (fs *OsFs) Rename(source, target string) error {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelDebug, "cross device copy error: %v", err)
|
fsLog(fs, logger.LevelError, "cross device copy error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.RemoveAll(source)
|
return os.RemoveAll(source)
|
||||||
|
@ -299,14 +299,14 @@ func (fs *OsFs) ResolvePath(virtualPath string) (string, error) {
|
||||||
// path chain until we hit a directory that _does_ exist and can be validated.
|
// path chain until we hit a directory that _does_ exist and can be validated.
|
||||||
_, err = fs.findFirstExistingDir(r)
|
_, err = fs.findFirstExistingDir(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "error resolving non-existent path %#v", err)
|
fsLog(fs, logger.LevelError, "error resolving non-existent path %#v", err)
|
||||||
}
|
}
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = fs.isSubDir(p)
|
err = fs.isSubDir(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
fsLog(fs, logger.LevelError, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
||||||
p, virtualPath, r, err)
|
p, virtualPath, r, err)
|
||||||
}
|
}
|
||||||
return r, err
|
return r, err
|
||||||
|
@ -358,7 +358,7 @@ func (fs *OsFs) findNonexistentDirs(filePath string) ([]string, error) {
|
||||||
}
|
}
|
||||||
err = fs.isSubDir(p)
|
err = fs.isSubDir(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "error finding non existing dir: %v", err)
|
fsLog(fs, logger.LevelError, "error finding non existing dir: %v", err)
|
||||||
}
|
}
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ func (fs *OsFs) findNonexistentDirs(filePath string) ([]string, error) {
|
||||||
func (fs *OsFs) findFirstExistingDir(path string) (string, error) {
|
func (fs *OsFs) findFirstExistingDir(path string) (string, error) {
|
||||||
results, err := fs.findNonexistentDirs(path)
|
results, err := fs.findNonexistentDirs(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "unable to find non existent dirs: %v", err)
|
fsLog(fs, logger.LevelError, "unable to find non existent dirs: %v", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
var parent string
|
var parent string
|
||||||
|
@ -395,7 +395,7 @@ func (fs *OsFs) isSubDir(sub string) error {
|
||||||
// fs.rootDir must exist and it is already a validated absolute path
|
// fs.rootDir must exist and it is already a validated absolute path
|
||||||
parent, err := filepath.EvalSymlinks(fs.rootDir)
|
parent, err := filepath.EvalSymlinks(fs.rootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "invalid root path %#v: %v", fs.rootDir, err)
|
fsLog(fs, logger.LevelError, "invalid root path %#v: %v", fs.rootDir, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if parent == sub {
|
if parent == sub {
|
||||||
|
|
|
@ -604,7 +604,7 @@ func (fs *S3Fs) getFileNamesInPrefix(fsPrefix string) (map[string]bool, error) {
|
||||||
})
|
})
|
||||||
metric.S3ListObjectsCompleted(err)
|
metric.S3ListObjectsCompleted(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "unable to get content for prefix %#v: %v", prefix, err)
|
fsLog(fs, logger.LevelError, "unable to get content for prefix %#v: %v", prefix, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return fileNames, err
|
return fileNames, err
|
||||||
|
|
|
@ -547,7 +547,7 @@ func (fs *SFTPFs) ResolvePath(virtualPath string) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
validatedPath, err = fs.getRealPath(fsPath)
|
validatedPath, err = fs.getRealPath(fsPath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
fsLog(fs, logger.LevelWarn, "Invalid path resolution, original path %v resolved %#v err: %v",
|
fsLog(fs, logger.LevelError, "Invalid path resolution, original path %v resolved %#v err: %v",
|
||||||
virtualPath, fsPath, err)
|
virtualPath, fsPath, err)
|
||||||
return "", err
|
return "", err
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
|
@ -560,13 +560,13 @@ func (fs *SFTPFs) ResolvePath(virtualPath string) (string, error) {
|
||||||
validatedPath, err = fs.getRealPath(validatedPath)
|
validatedPath, err = fs.getRealPath(validatedPath)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
fsLog(fs, logger.LevelError, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
||||||
validatedPath, virtualPath, fsPath, err)
|
validatedPath, virtualPath, fsPath, err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := fs.isSubDir(validatedPath); err != nil {
|
if err := fs.isSubDir(validatedPath); err != nil {
|
||||||
fsLog(fs, logger.LevelWarn, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
fsLog(fs, logger.LevelError, "Invalid path resolution, dir %#v original path %#v resolved %#v err: %v",
|
||||||
validatedPath, virtualPath, fsPath, err)
|
validatedPath, virtualPath, fsPath, err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -727,7 +727,7 @@ func (fs *SFTPFs) createConnection() error {
|
||||||
fp := ssh.FingerprintSHA256(key)
|
fp := ssh.FingerprintSHA256(key)
|
||||||
if util.IsStringInSlice(fp, sftpFingerprints) {
|
if util.IsStringInSlice(fp, sftpFingerprints) {
|
||||||
if util.IsStringInSlice(fs.config.Username, fs.config.forbiddenSelfUsernames) {
|
if util.IsStringInSlice(fs.config.Username, fs.config.forbiddenSelfUsernames) {
|
||||||
fsLog(fs, logger.LevelWarn, "SFTP loop or nested local SFTP folders detected, mount path %#v, username %#v, forbidden usernames: %+v",
|
fsLog(fs, logger.LevelError, "SFTP loop or nested local SFTP folders detected, mount path %#v, username %#v, forbidden usernames: %+v",
|
||||||
fs.mountPath, fs.config.Username, fs.config.forbiddenSelfUsernames)
|
fs.mountPath, fs.config.Username, fs.config.forbiddenSelfUsernames)
|
||||||
return ErrSFTPLoop
|
return ErrSFTPLoop
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ func (c *Connection) getFile(fs vfs.Fs, fsPath, virtualPath string) (webdav.File
|
||||||
if vfs.IsLocalOrUnbufferedSFTPFs(fs) {
|
if vfs.IsLocalOrUnbufferedSFTPFs(fs) {
|
||||||
file, r, cancelFn, err = fs.Open(fsPath, 0)
|
file, r, cancelFn, err = fs.Open(fsPath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "could not open file %#v for reading: %+v", fsPath, err)
|
c.Log(logger.LevelError, "could not open file %#v for reading: %+v", fsPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (c *Connection) putFile(fs vfs.Fs, fsPath, virtualPath string) (webdav.File
|
||||||
|
|
||||||
// This happen if we upload a file that has the same name of an existing directory
|
// This happen if we upload a file that has the same name of an existing directory
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
c.Log(logger.LevelWarn, "attempted to open a directory for writing to: %#v", fsPath)
|
c.Log(logger.LevelError, "attempted to open a directory for writing to: %#v", fsPath)
|
||||||
return nil, c.GetOpUnsupportedError()
|
return nil, c.GetOpUnsupportedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ func (c *Connection) handleUploadToNewFile(fs vfs.Fs, resolvedPath, filePath, re
|
||||||
}
|
}
|
||||||
file, w, cancelFn, err := fs.Create(filePath, 0)
|
file, w, cancelFn, err := fs.Create(filePath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error creating file %#v: %+v", resolvedPath, err)
|
c.Log(logger.LevelError, "error creating file %#v: %+v", resolvedPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ func (c *Connection) handleUploadToExistingFile(fs vfs.Fs, resolvedPath, filePat
|
||||||
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
if common.Config.IsAtomicUploadEnabled() && fs.IsAtomicUploadSupported() {
|
||||||
err = fs.Rename(resolvedPath, filePath)
|
err = fs.Rename(resolvedPath, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
c.Log(logger.LevelError, "error renaming existing file for atomic upload, source: %#v, dest: %#v, err: %+v",
|
||||||
resolvedPath, filePath, err)
|
resolvedPath, filePath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ func (c *Connection) handleUploadToExistingFile(fs vfs.Fs, resolvedPath, filePat
|
||||||
|
|
||||||
file, w, cancelFn, err := fs.Create(filePath, 0)
|
file, w, cancelFn, err := fs.Create(filePath, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "error creating file %#v: %+v", resolvedPath, err)
|
c.Log(logger.LevelError, "error creating file %#v: %+v", resolvedPath, err)
|
||||||
return nil, c.GetFsError(fs, err)
|
return nil, c.GetFsError(fs, err)
|
||||||
}
|
}
|
||||||
initialSize := int64(0)
|
initialSize := int64(0)
|
||||||
|
@ -320,7 +320,7 @@ func (c *Connection) removeDirTree(fs vfs.Fs, fsPath, virtualPath string) error
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log(logger.LevelWarn, "failed to remove dir tree %#v->%#v: error: %+v", virtualPath, fsPath, err)
|
c.Log(logger.LevelError, "failed to remove dir tree %#v->%#v: error: %+v", virtualPath, fsPath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue