Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/httpd/sftpvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type sftpFileSystem interface {
OpenUploadTemp(string, bool) (*srvconn.SftpFile, error)
CommitUploadTemp(string, string, bool) (*model.FTPLog, error)
OpenForChecksum(string) (*srvconn.SftpFile, error)
AtomicCreate(string, string) error
AtomicCreate(string, string) (*model.FTPLog, error)
AtomicReplace(string, string) error
DiscardUploadTemp(string) error
ResolveAgentToolPath(string) (string, error)
Expand Down
11 changes: 8 additions & 3 deletions pkg/httpd/sftpvolume_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ func (u *sftpVolume) SaveFile(
}
}()

fd, err := u.conn.CreateEditorTemp(tempPath, path)
createOnly := options.expectedVersion != nil && !options.force && *options.expectedVersion == webSftpAbsentVersion
var fd *srvconn.SftpFile
if createOnly {
fd, err = u.conn.OpenUploadTemp(tempPath, true)
} else {
fd, err = u.conn.CreateEditorTemp(tempPath, path)
}
if err != nil {
return result, err
}
Expand All @@ -309,9 +315,8 @@ func (u *sftpVolume) SaveFile(
if err := u.check(ctx); err != nil {
return result, err
}
createOnly := options.expectedVersion != nil && !options.force && *options.expectedVersion == webSftpAbsentVersion
if createOnly {
err = u.conn.AtomicCreate(tempPath, path)
fd.FTPLog, err = u.conn.AtomicCreate(tempPath, path)
} else {
err = u.conn.AtomicReplace(tempPath, path)
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/srvconn/sftp_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,22 +575,27 @@ func (ad *AssetDir) AtomicReplace(sourcePath, targetPath string) error {
return nil
}

func (ad *AssetDir) AtomicCreate(sourcePath, targetPath string) error {
func (ad *AssetDir) AtomicCreate(sourcePath, targetPath string) (*model.FTPLog, error) {
_, sourceConn, sourceRealPath, err := ad.resolveUploadPath(sourcePath)
if err != nil {
return err
return nil, err
}
_, targetConn, targetRealPath, err := ad.resolveUploadPath(targetPath)
su, targetConn, targetRealPath, err := ad.resolveUploadPath(targetPath)
if err != nil {
return err
return nil, err
}
if sourceConn != targetConn {
return sftp.ErrSshFxOpUnsupported
return nil, sftp.ErrSshFxOpUnsupported
}

sourceConn.IncreaseRef()
defer sourceConn.DecreaseRef()
return sourceConn.client.Rename(sourceRealPath, targetRealPath)
if _, err = sourceConn.client.Stat(targetRealPath); err == nil {
err = os.ErrExist
} else if os.IsNotExist(err) {
err = sourceConn.client.Rename(sourceRealPath, targetRealPath)
}
return ad.CreateFTPLog(su, "create", targetRealPath, err == nil), err
}

func (ad *AssetDir) DiscardUploadTemp(path string) error {
Expand Down
7 changes: 4 additions & 3 deletions pkg/srvconn/sftpconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,19 @@ func (u *UserSftpConn) AtomicReplace(sourcePath, targetPath string) error {
return sourceAssetDir.AtomicReplace(sourceRestPath, targetRestPath)
}

func (u *UserSftpConn) AtomicCreate(sourcePath, targetPath string) error {
func (u *UserSftpConn) AtomicCreate(sourcePath, targetPath string) (*model.FTPLog, error) {
if u.assetDir != nil {
return u.assetDir.AtomicCreate(sourcePath, targetPath)
}

sourceFi, sourceRestPath := u.ParsePath(sourcePath)
targetFi, targetRestPath := u.ParsePath(targetPath)
sourceAssetDir, ok := sourceFi.(*AssetDir)
if !ok {
return sftp.ErrSshFxPermissionDenied
return nil, sftp.ErrSshFxPermissionDenied
}
if targetAssetDir, targetOk := targetFi.(*AssetDir); !targetOk || targetAssetDir != sourceAssetDir {
return sftp.ErrSshFxOpUnsupported
return nil, sftp.ErrSshFxOpUnsupported
}
return sourceAssetDir.AtomicCreate(sourceRestPath, targetRestPath)
}
Expand Down
Loading