mirror of
https://github.com/minio/minio.git
synced 2025-03-03 07:10:07 -05:00
Make sure to delete uploadid's from active session file properly
This commit is contained in:
parent
0d3710cb9b
commit
e08d59be00
@ -142,21 +142,6 @@ func (fs *fsDriver) NewMultipartUpload(bucket, key, contentType string) (string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", iodine.New(drivers.InternalError{}, nil)
|
return "", iodine.New(drivers.InternalError{}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var activeSessionFile *os.File
|
|
||||||
if _, err := os.Stat(bucketPath + "$activeSession"); os.IsNotExist(err) {
|
|
||||||
activeSessionFile, err = os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY|os.O_CREATE, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return "", iodine.New(err, nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
activeSessionFile, err = os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return "", iodine.New(err, nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer activeSessionFile.Close()
|
|
||||||
|
|
||||||
objectPath := path.Join(bucketPath, key)
|
objectPath := path.Join(bucketPath, key)
|
||||||
objectDir := path.Dir(objectPath)
|
objectDir := path.Dir(objectPath)
|
||||||
if _, err := os.Stat(objectDir); os.IsNotExist(err) {
|
if _, err := os.Stat(objectDir); os.IsNotExist(err) {
|
||||||
@ -174,6 +159,20 @@ func (fs *fsDriver) NewMultipartUpload(bucket, key, contentType string) (string,
|
|||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var activeSessionFile *os.File
|
||||||
|
if _, err := os.Stat(bucketPath + "$activeSession"); os.IsNotExist(err) {
|
||||||
|
activeSessionFile, err = os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return "", iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
activeSessionFile, err = os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return "", iodine.New(err, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer activeSessionFile.Close()
|
||||||
|
|
||||||
id := []byte(strconv.FormatInt(rand.Int63(), 10) + bucket + key + time.Now().String())
|
id := []byte(strconv.FormatInt(rand.Int63(), 10) + bucket + key + time.Now().String())
|
||||||
uploadIDSum := sha512.Sum512(id)
|
uploadIDSum := sha512.Sum512(id)
|
||||||
uploadID := base64.URLEncoding.EncodeToString(uploadIDSum[:])[:47]
|
uploadID := base64.URLEncoding.EncodeToString(uploadIDSum[:])[:47]
|
||||||
@ -336,7 +335,7 @@ func (fs *fsDriver) CreateObjectPart(bucket, key, uploadID string, partID int, c
|
|||||||
}
|
}
|
||||||
deserializedMultipartSession.Parts = append(deserializedMultipartSession.Parts, &partMetadata)
|
deserializedMultipartSession.Parts = append(deserializedMultipartSession.Parts, &partMetadata)
|
||||||
deserializedMultipartSession.TotalParts++
|
deserializedMultipartSession.TotalParts++
|
||||||
fs.multiparts.ActiveSession[uploadID] = &deserializedMultipartSession
|
fs.multiparts.ActiveSession[key] = &deserializedMultipartSession
|
||||||
|
|
||||||
sort.Sort(partNumber(deserializedMultipartSession.Parts))
|
sort.Sort(partNumber(deserializedMultipartSession.Parts))
|
||||||
encoder := json.NewEncoder(multiPartfile)
|
encoder := json.NewEncoder(multiPartfile)
|
||||||
@ -425,7 +424,7 @@ func (fs *fsDriver) CompleteMultipartUpload(bucket, key, uploadID string, parts
|
|||||||
}
|
}
|
||||||
md5sum := hex.EncodeToString(h.Sum(nil))
|
md5sum := hex.EncodeToString(h.Sum(nil))
|
||||||
|
|
||||||
delete(fs.multiparts.ActiveSession, uploadID)
|
delete(fs.multiparts.ActiveSession, key)
|
||||||
for partNumber := range parts {
|
for partNumber := range parts {
|
||||||
err = os.Remove(objectPath + fmt.Sprintf("$%d", partNumber))
|
err = os.Remove(objectPath + fmt.Sprintf("$%d", partNumber))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -454,11 +453,12 @@ func (fs *fsDriver) CompleteMultipartUpload(bucket, key, uploadID string, parts
|
|||||||
return "", iodine.New(err, nil)
|
return "", iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
activeSessionFile, err := os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY, 0600)
|
activeSessionFile, err := os.OpenFile(bucketPath+"$activeSession", os.O_WRONLY|os.O_TRUNC, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", iodine.New(err, nil)
|
return "", iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
defer activeSessionFile.Close()
|
defer activeSessionFile.Close()
|
||||||
|
fmt.Println(fs.multiparts.ActiveSession)
|
||||||
encoder = json.NewEncoder(activeSessionFile)
|
encoder = json.NewEncoder(activeSessionFile)
|
||||||
err = encoder.Encode(fs.multiparts.ActiveSession)
|
err = encoder.Encode(fs.multiparts.ActiveSession)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -577,7 +577,7 @@ func (fs *fsDriver) AbortMultipartUpload(bucket, key, uploadID string) error {
|
|||||||
}
|
}
|
||||||
multiPartfile.Close() // close it right here, since we will delete it subsequently
|
multiPartfile.Close() // close it right here, since we will delete it subsequently
|
||||||
|
|
||||||
delete(fs.multiparts.ActiveSession, uploadID)
|
delete(fs.multiparts.ActiveSession, key)
|
||||||
for _, part := range deserializedMultipartSession.Parts {
|
for _, part := range deserializedMultipartSession.Parts {
|
||||||
err = os.RemoveAll(objectPath + fmt.Sprintf("$%d", part.PartNumber))
|
err = os.RemoveAll(objectPath + fmt.Sprintf("$%d", part.PartNumber))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user