filer: option to create file only if it is new, O_EXCL

This commit is contained in:
Chris Lu
2020-01-22 11:42:40 -08:00
parent 9b01a99d9a
commit d4e75a0d18
11 changed files with 140 additions and 122 deletions

View File

@@ -139,7 +139,7 @@ func (fs *FilerServer) CreateEntry(ctx context.Context, req *filer_pb.CreateEntr
FullPath: fullpath,
Attr: filer2.PbToEntryAttribute(req.Entry.Attributes),
Chunks: chunks,
})
}, req.OExcl)
if err == nil {
fs.filer.DeleteChunks(garbages)

View File

@@ -107,7 +107,7 @@ func (fs *FilerServer) moveSelfEntry(ctx context.Context, oldParent filer2.FullP
Attr: entry.Attr,
Chunks: entry.Chunks,
}
createErr := fs.filer.CreateEntry(ctx, newEntry)
createErr := fs.filer.CreateEntry(ctx, newEntry, false)
if createErr != nil {
return createErr
}

View File

@@ -193,7 +193,7 @@ func (fs *FilerServer) updateFilerStore(ctx context.Context, r *http.Request, w
entry.Attr.Mime = mime.TypeByExtension(ext)
}
// glog.V(4).Infof("saving %s => %+v", path, entry)
if dbErr := fs.filer.CreateEntry(ctx, entry); dbErr != nil {
if dbErr := fs.filer.CreateEntry(ctx, entry, false); dbErr != nil {
fs.filer.DeleteChunks(entry.Chunks)
glog.V(0).Infof("failing to write %s to filer server : %v", path, dbErr)
writeJsonError(w, r, http.StatusInternalServerError, dbErr)

View File

@@ -176,7 +176,7 @@ func (fs *FilerServer) doAutoChunk(ctx context.Context, w http.ResponseWriter, r
},
Chunks: fileChunks,
}
if dbErr := fs.filer.CreateEntry(ctx, entry); dbErr != nil {
if dbErr := fs.filer.CreateEntry(ctx, entry, false); dbErr != nil {
fs.filer.DeleteChunks(entry.Chunks)
replyerr = dbErr
filerResult.Error = dbErr.Error()