Skip to content

Commit

Permalink
Show the proper local and remote destination of deployed files
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed Jun 20, 2021
1 parent 3ec9bb2 commit a55d4ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func init() {
"errors.stor.failed": "Could not store file %s over FTP: %s",

"debug.mkdir.success": "Successfully created directory %s on server",
"debug.stor.success": "Successfully stored file %s on server",
"debug.stor.success": "Successfully stored local file %s to <remote>:%s",
"debug.cwd": "Changing directory to %s",
"debug.dir.skip": "Skipping directory %s that exists on target",
"debug.file.skip": "Skipping file %s that exists on target (no overwrite specified)",
Expand Down
16 changes: 10 additions & 6 deletions internal/upload/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package upload
import (
"crypto/tls"
"os"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -134,15 +135,18 @@ func (c *ftpConnection) UploadFile(
return err
}

localFileName := filepath.Join(".", fileName)
remoteFileName := filepath.Join(serverRoot, basePath, baseName)

entry, err := c.findFile(serverRoot+basePath, baseName)
if entry != nil && err == nil {
if file.IsDir() && entry.Type == ftp.EntryTypeFolder {
utils.Log.Debug(locales.L.Get("debug.dir.skip", fileName))
utils.Log.Debug(locales.L.Get("debug.dir.skip", localFileName))
return nil
}

if !file.IsDir() && entry.Type == ftp.EntryTypeFile && !overwrite {
utils.Log.Debug(locales.L.Get("debug.file.skip", fileName))
utils.Log.Debug(locales.L.Get("debug.file.skip", localFileName))
return nil
}
}
Expand All @@ -151,9 +155,9 @@ func (c *ftpConnection) UploadFile(
err = c.inner.MakeDir(baseName)

if err != nil {
utils.Log.Error(locales.L.Get("errors.mkdir.failed", clientRoot+baseName, err.Error()))
utils.Log.Error(locales.L.Get("errors.mkdir.failed", localFileName, err.Error()))
} else {
utils.Log.Debug(locales.L.Get("debug.mkdir.success", clientRoot+baseName))
utils.Log.Debug(locales.L.Get("debug.mkdir.success", localFileName))
}
} else {
file, err := os.Open(clientRoot + basePath + baseName)
Expand All @@ -163,9 +167,9 @@ func (c *ftpConnection) UploadFile(
err = c.inner.Stor(baseName, file)

if err != nil {
utils.Log.Error(locales.L.Get("errors.stor.failed", clientRoot+baseName, err.Error()))
utils.Log.Error(locales.L.Get("errors.stor.failed", localFileName, err.Error()))
} else {
utils.Log.Print(locales.L.Get("debug.stor.success", clientRoot+baseName))
utils.Log.Print(locales.L.Get("debug.stor.success", localFileName, remoteFileName))
}
}

Expand Down

0 comments on commit a55d4ae

Please sign in to comment.