From 87ced5f95d151c51eecbf17c63114a85af1b5773 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sat, 29 Dec 2018 23:55:50 +0100 Subject: nametransform: Delete incomplete longname files on error. --- internal/nametransform/longnames.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'internal') diff --git a/internal/nametransform/longnames.go b/internal/nametransform/longnames.go index 01280a8..da18ebb 100644 --- a/internal/nametransform/longnames.go +++ b/internal/nametransform/longnames.go @@ -122,10 +122,20 @@ func (n *NameTransform) WriteLongName(dirfd int, hashName string, plainName stri return err } fd := os.NewFile(uintptr(fdRaw), hashName+LongNameSuffix) - defer fd.Close() _, err = fd.Write([]byte(cName)) if err != nil { + fd.Close() tlog.Warn.Printf("WriteLongName: Write: %v", err) + // Delete incomplete longname file + syscallcompat.Unlinkat(dirfd, hashName+LongNameSuffix, 0) + return err } - return err + err = fd.Close() + if err != nil { + tlog.Warn.Printf("WriteLongName: Close: %v", err) + // Delete incomplete longname file + syscallcompat.Unlinkat(dirfd, hashName+LongNameSuffix, 0) + return err + } + return nil } -- cgit v1.2.3