Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions backend/internxt/internxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ func (f *Fs) preUploadCheck(ctx context.Context, leaf, directoryID string) (*fol
}

if len(checkResult.Files) > 0 && checkResult.Files[0].FileExists() {
existingUUID := checkResult.Files[0].UUID
result := checkResult.Files[0]
if result.Type != ext {
return nil, nil
}

existingUUID := result.UUID
if existingUUID != "" {
fileMeta, err := files.GetFileMeta(ctx, f.cfg, existingUUID)
if err == nil && fileMeta != nil {
Expand Down Expand Up @@ -616,16 +621,14 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
if err != nil {
return nil, err
}
targetName := filepath.Base(remote)
for _, e := range files {
name := e.PlainName
if len(e.Type) > 0 {
name += "." + e.Type
}
decodedName := f.opt.Encoding.ToStandardName(name)
targetName := filepath.Base(remote)
match := decodedName == targetName

if match {
if decodedName == targetName {
return newObjectWithFile(f, remote, &e), nil
}
}
Expand Down Expand Up @@ -819,6 +822,11 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return shouldRetry(ctx, err)
})

if err != nil && isEmptyFileLimitError(err) {
o.restoreBackupFile(ctx, backupUUID, origName, origType)
return fs.ErrorCantUploadEmptyFiles
}

if err != nil {
meta, err = o.recoverFromTimeoutConflict(ctx, err, remote, dirID)
}
Expand Down Expand Up @@ -883,6 +891,13 @@ func isConflictError(err error) bool {
strings.Contains(errMsg, "already exists")
}

func isEmptyFileLimitError(err error) bool {
errMsg := strings.ToLower(err.Error())
return strings.Contains(errMsg, "can not have more empty files") ||
strings.Contains(errMsg, "cannot have more empty files") ||
strings.Contains(errMsg, "you can not have empty files")
}

// recoverFromTimeoutConflict attempts to recover from a timeout or conflict error
func (o *Object) recoverFromTimeoutConflict(ctx context.Context, uploadErr error, remote, dirID string) (*buckets.CreateMetaResponse, error) {
if !isTimeoutError(uploadErr) && !isConflictError(uploadErr) {
Expand Down