X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/c6a3fa2cdbf7eb78964a5df7622482cdd8782d74..45ca5d60383cbe270624c713b916da29af7ba88f:/hotline/file_wrapper.go diff --git a/hotline/file_wrapper.go b/hotline/file_wrapper.go index f3fd559..342355b 100644 --- a/hotline/file_wrapper.go +++ b/hotline/file_wrapper.go @@ -1,6 +1,7 @@ package hotline import ( + "bytes" "encoding/binary" "errors" "fmt" @@ -26,8 +27,6 @@ type fileWrapper struct { rsrcPath string // path to the file resource fork infoPath string // path to the file information fork incompletePath string // path to partially transferred temp file - saveMetaData bool // if true, enables saving of info and resource forks in sidecar files - infoFork *FlatFileInformationFork ffo *flattenedFileObject } @@ -115,7 +114,7 @@ func (f *fileWrapper) rsrcForkWriter() (io.WriteCloser, error) { } func (f *fileWrapper) infoForkWriter() (io.WriteCloser, error) { - file, err := os.OpenFile(f.infoPath, os.O_CREATE|os.O_WRONLY, 0644) + file, err := os.OpenFile(f.infoPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { return nil, err } @@ -151,26 +150,31 @@ func (f *fileWrapper) dataFile() (os.FileInfo, error) { return nil, errors.New("file or directory not found") } -// move a fileWrapper and its associated metadata files to newPath +// move a fileWrapper and its associated meta files to newPath. +// Meta files include: +// * Partially uploaded file ending with .incomplete +// * Resource fork starting with .rsrc_ +// * Info fork starting with .info +// During move of the meta files, os.ErrNotExist is ignored as these files may legitimately not exist. func (f *fileWrapper) move(newPath string) error { err := f.fs.Rename(f.dataPath, filepath.Join(newPath, f.name)) if err != nil { - // TODO + return err } err = f.fs.Rename(f.incompletePath, filepath.Join(newPath, f.incompleteDataName())) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } err = f.fs.Rename(f.rsrcPath, filepath.Join(newPath, f.rsrcForkName())) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } err = f.fs.Rename(f.infoPath, filepath.Join(newPath, f.infoForkName())) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } return nil @@ -180,22 +184,22 @@ func (f *fileWrapper) move(newPath string) error { func (f *fileWrapper) delete() error { err := f.fs.RemoveAll(f.dataPath) if err != nil { - // TODO + return err } err = f.fs.Remove(f.incompletePath) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } err = f.fs.Remove(f.rsrcPath) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } err = f.fs.Remove(f.infoPath) - if err != nil { - // TODO + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } return nil @@ -203,7 +207,7 @@ func (f *fileWrapper) delete() error { func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { dataSize := make([]byte, 4) - mTime := make([]byte, 8) + mTime := [8]byte{} ft := defaultFileType @@ -240,9 +244,11 @@ func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { f.ffo.FlatFileHeader.ForkCount[1] = 3 - if err := f.ffo.FlatFileInformationFork.UnmarshalBinary(b); err != nil { - return nil, err + _, err = io.Copy(&f.ffo.FlatFileInformationFork, bytes.NewReader(b)) + if err != nil { + return nil, fmt.Errorf("error copying FlatFileInformationFork: %w", err) } + } else { f.ffo.FlatFileInformationFork = FlatFileInformationFork{ Platform: []byte("AMAC"), // TODO: Remove hardcode to support "AWIN" Platform (maybe?) @@ -251,8 +257,8 @@ func (f *fileWrapper) flattenedFileObject() (*flattenedFileObject, error) { Flags: []byte{0, 0, 0, 0}, PlatformFlags: []byte{0, 0, 1, 0}, // TODO: What is this? RSVD: make([]byte, 32), - CreateDate: mTime, // some filesystems don't support createTime - ModifyDate: mTime, + CreateDate: mTime[:], // some filesystems don't support createTime + ModifyDate: mTime[:], NameScript: []byte{0, 0}, Name: []byte(f.name), NameSize: []byte{0, 0},