Merge pull request #1506 from harshavardhana/fs-cp
cp: Working resumable cp fixes #1505
This commit is contained in:
@@ -106,6 +106,13 @@ func (e PathNotFound) Error() string {
|
||||
return "Requested file ‘" + e.Path + "’ not found"
|
||||
}
|
||||
|
||||
// PathIsDir (EISDIR) - file is a folder.
|
||||
type PathIsDir GenericFileError
|
||||
|
||||
func (e PathIsDir) Error() string {
|
||||
return "Requested file ‘" + e.Path + "’ is folder."
|
||||
}
|
||||
|
||||
// PathInsufficientPermission (EPERM) - permission denied.
|
||||
type PathInsufficientPermission GenericFileError
|
||||
|
||||
|
||||
@@ -125,6 +125,24 @@ func (f *fsClient) Put(data io.ReadSeeker, size int64) *probe.Error {
|
||||
objectDir, _ := filepath.Split(f.PathURL.Path)
|
||||
objectPath := f.PathURL.Path
|
||||
|
||||
// Verify if destination already exists.
|
||||
st, e := os.Stat(objectPath)
|
||||
if e == nil {
|
||||
// If the destination exists and is a directory.
|
||||
if st.IsDir() {
|
||||
return probe.NewError(client.PathIsDir{
|
||||
Path: objectPath,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Proceed if file does not exist. return for all other errors.
|
||||
if e != nil {
|
||||
if !os.IsNotExist(e) {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Write to a temporary file "object.part.mc" before commiting.
|
||||
objectPartPath := objectPath + partSuffix
|
||||
|
||||
@@ -151,6 +169,15 @@ func (f *fsClient) Put(data io.ReadSeeker, size int64) *probe.Error {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
// Get stat to get the current size.
|
||||
partSt, e := partFile.Stat()
|
||||
if e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
// Seek to current position for incoming reader.
|
||||
data.Seek(partSt.Size(), 0)
|
||||
|
||||
// Write to the part file.
|
||||
if size < 0 { // Read till EOF.
|
||||
_, e = io.Copy(partFile, data)
|
||||
|
||||
Reference in New Issue
Block a user