Merge pull request #1506 from harshavardhana/fs-cp

cp: Working resumable cp fixes #1505
This commit is contained in:
Harshavardhana
2015-11-30 11:05:08 -08:00
2 changed files with 34 additions and 0 deletions
+7
View File
@@ -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
+27
View File
@@ -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)