|
@ -126,10 +126,6 @@ func (fs *FilerServer) doPutAutoChunk(ctx context.Context, w http.ResponseWriter |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func isAppend(r *http.Request) bool { |
|
|
|
|
|
return r.URL.Query().Get("op") == "append" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileName string, contentType string, so *operation.StorageOption, md5bytes []byte, fileChunks []*filer_pb.FileChunk, chunkOffset int64, content []byte) (filerResult *FilerPostResult, replyerr error) { |
|
|
func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileName string, contentType string, so *operation.StorageOption, md5bytes []byte, fileChunks []*filer_pb.FileChunk, chunkOffset int64, content []byte) (filerResult *FilerPostResult, replyerr error) { |
|
|
|
|
|
|
|
|
// detect file mode
|
|
|
// detect file mode
|
|
@ -161,8 +157,11 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa |
|
|
|
|
|
|
|
|
var entry *filer.Entry |
|
|
var entry *filer.Entry |
|
|
var mergedChunks []*filer_pb.FileChunk |
|
|
var mergedChunks []*filer_pb.FileChunk |
|
|
|
|
|
|
|
|
|
|
|
isAppend := r.URL.Query().Get("op") == "append" |
|
|
|
|
|
isOffsetWrite := fileChunks[0].Offset > 0 |
|
|
// when it is an append
|
|
|
// when it is an append
|
|
|
if isAppend(r) { |
|
|
|
|
|
|
|
|
if isAppend || isOffsetWrite { |
|
|
existingEntry, findErr := fs.filer.FindEntry(ctx, util.FullPath(path)) |
|
|
existingEntry, findErr := fs.filer.FindEntry(ctx, util.FullPath(path)) |
|
|
if findErr != nil && findErr != filer_pb.ErrNotFound { |
|
|
if findErr != nil && findErr != filer_pb.ErrNotFound { |
|
|
glog.V(0).Infof("failing to find %s: %v", path, findErr) |
|
|
glog.V(0).Infof("failing to find %s: %v", path, findErr) |
|
@ -173,11 +172,13 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa |
|
|
entry.Mtime = time.Now() |
|
|
entry.Mtime = time.Now() |
|
|
entry.Md5 = nil |
|
|
entry.Md5 = nil |
|
|
// adjust chunk offsets
|
|
|
// adjust chunk offsets
|
|
|
for _, chunk := range fileChunks { |
|
|
|
|
|
chunk.Offset += int64(entry.FileSize) |
|
|
|
|
|
|
|
|
if isAppend { |
|
|
|
|
|
for _, chunk := range fileChunks { |
|
|
|
|
|
chunk.Offset += int64(entry.FileSize) |
|
|
|
|
|
} |
|
|
|
|
|
entry.FileSize += uint64(chunkOffset) |
|
|
} |
|
|
} |
|
|
mergedChunks = append(entry.Chunks, fileChunks...) |
|
|
mergedChunks = append(entry.Chunks, fileChunks...) |
|
|
entry.FileSize += uint64(chunkOffset) |
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
// TODO
|
|
|
if len(entry.Content) > 0 { |
|
|
if len(entry.Content) > 0 { |
|
@ -215,6 +216,10 @@ func (fs *FilerServer) saveMetaData(ctx context.Context, r *http.Request, fileNa |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
entry.Chunks = mergedChunks |
|
|
entry.Chunks = mergedChunks |
|
|
|
|
|
if isOffsetWrite { |
|
|
|
|
|
entry.Md5 = nil |
|
|
|
|
|
entry.FileSize = entry.Size() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
filerResult = &FilerPostResult{ |
|
|
filerResult = &FilerPostResult{ |
|
|
Name: fileName, |
|
|
Name: fileName, |
|
|