diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 27f9a3c..093524d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,6 +6,7 @@ builds: - goos: - linux - darwin + - freebsd # windows is untested, we can start doing windows releases # if someone is interested in taking on testing # - windows diff --git a/backend/posix/posix.go b/backend/posix/posix.go index fe6e42a..a3f53a9 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -435,7 +435,7 @@ func loadUserMetaData(path string, m map[string]string) (contentType, contentEnc continue } b, err := xattr.Get(path, e) - if err == syscall.ENODATA { + if err == errNoData { m[strings.TrimPrefix(e, fmt.Sprintf("user.%v.", metaHdr))] = "" continue } @@ -1934,7 +1934,7 @@ func isNoAttr(err error) bool { if ok && xerr.Err == xattr.ENOATTR { return true } - if err == syscall.ENODATA { + if err == errNoData { return true } return false diff --git a/backend/posix/posix_windows.go b/backend/posix/posix_windows.go deleted file mode 100644 index e67f93b..0000000 --- a/backend/posix/posix_windows.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2023 Versity Software -// This file is licensed under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package posix - -import ( - "crypto/sha256" - "errors" - "fmt" - "io/fs" - "os" - "path/filepath" -) - -type tmpfile struct { - f *os.File - bucket string - objname string - size int64 -} - -func openTmpFile(dir, bucket, obj string, size int64) (*tmpfile, error) { - // Create a temp file for upload while in progress (see link comments below). - err := os.MkdirAll(dir, 0700) - if err != nil { - return nil, fmt.Errorf("make temp dir: %w", err) - } - f, err := os.CreateTemp(dir, - fmt.Sprintf("%x.", sha256.Sum256([]byte(obj)))) - if err != nil { - return nil, err - } - return &tmpfile{f: f, bucket: bucket, objname: obj, size: size}, nil -} - -func (tmp *tmpfile) link() error { - tempname := tmp.f.Name() - // cleanup in case anything goes wrong, if rename succeeds then - // this will no longer exist - defer os.Remove(tempname) - - // We use Rename as the atomic operation for object puts. The upload is - // written to a temp file to not conflict with any other simultaneous - // uploads. The final operation is to move the temp file into place for - // the object. This ensures the object semantics of last upload completed - // wins and is not some combination of writes from simultaneous uploads. - objPath := filepath.Join(tmp.bucket, tmp.objname) - err := os.Remove(objPath) - if err != nil && !errors.Is(err, fs.ErrNotExist) { - return fmt.Errorf("remove stale path: %w", err) - } - - err = tmp.f.Close() - if err != nil { - return fmt.Errorf("close tmpfile: %w", err) - } - - err = os.Rename(tempname, objPath) - if err != nil { - return fmt.Errorf("rename tmpfile: %w", err) - } - - return nil -} - -func (tmp *tmpfile) Write(b []byte) (int, error) { - if int64(len(b)) > tmp.size { - return 0, fmt.Errorf("write exceeds content length") - } - - n, err := tmp.f.Write(b) - tmp.size -= int64(n) - return n, err -} - -func (tmp *tmpfile) cleanup() { - tmp.f.Close() -} diff --git a/backend/posix/with_enodata.go b/backend/posix/with_enodata.go new file mode 100644 index 0000000..d89e0a9 --- /dev/null +++ b/backend/posix/with_enodata.go @@ -0,0 +1,24 @@ +// Copyright 2024 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !freebsd && !openbsd && !netbsd +// +build !freebsd,!openbsd,!netbsd + +package posix + +import "syscall" + +var ( + errNoData = syscall.ENODATA +) diff --git a/backend/posix/posix_linux.go b/backend/posix/with_otmpfile.go similarity index 99% rename from backend/posix/posix_linux.go rename to backend/posix/with_otmpfile.go index accf4ad..256a636 100644 --- a/backend/posix/posix_linux.go +++ b/backend/posix/with_otmpfile.go @@ -12,6 +12,9 @@ // specific language governing permissions and limitations // under the License. +//go:build linux +// +build linux + package posix import ( diff --git a/backend/posix/without_enodata.go b/backend/posix/without_enodata.go new file mode 100644 index 0000000..b080346 --- /dev/null +++ b/backend/posix/without_enodata.go @@ -0,0 +1,24 @@ +// Copyright 2024 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build freebsd || openbsd || netbsd +// +build freebsd openbsd netbsd + +package posix + +import "syscall" + +var ( + errNoData = syscall.ENOATTR +) diff --git a/backend/posix/posix_darwin.go b/backend/posix/without_otmpfile.go similarity index 98% rename from backend/posix/posix_darwin.go rename to backend/posix/without_otmpfile.go index 819d78f..3c793b9 100644 --- a/backend/posix/posix_darwin.go +++ b/backend/posix/without_otmpfile.go @@ -12,6 +12,9 @@ // specific language governing permissions and limitations // under the License. +//go:build !linux +// +build !linux + package posix import ( diff --git a/backend/scoutfs/scoutfs.go b/backend/scoutfs/scoutfs.go index 160a350..090e9e9 100644 --- a/backend/scoutfs/scoutfs.go +++ b/backend/scoutfs/scoutfs.go @@ -25,7 +25,6 @@ import ( "os" "path/filepath" "strings" - "syscall" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" @@ -267,7 +266,7 @@ func loadUserMetaData(path string, m map[string]string) (contentType, contentEnc continue } b, err := xattr.Get(path, e) - if err == syscall.ENODATA { + if err == errNoData { m[strings.TrimPrefix(e, "user.")] = "" continue } @@ -805,7 +804,7 @@ func isNoAttr(err error) bool { if ok && xerr.Err == xattr.ENOATTR { return true } - if err == syscall.ENODATA { + if err == errNoData { return true } return false diff --git a/backend/scoutfs/with_enodata.go b/backend/scoutfs/with_enodata.go new file mode 100644 index 0000000..6d41d1d --- /dev/null +++ b/backend/scoutfs/with_enodata.go @@ -0,0 +1,24 @@ +// Copyright 2024 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !freebsd && !openbsd && !netbsd +// +build !freebsd,!openbsd,!netbsd + +package scoutfs + +import "syscall" + +var ( + errNoData = syscall.ENODATA +) diff --git a/backend/scoutfs/without_enodata.go b/backend/scoutfs/without_enodata.go new file mode 100644 index 0000000..c621fc6 --- /dev/null +++ b/backend/scoutfs/without_enodata.go @@ -0,0 +1,24 @@ +// Copyright 2024 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build freebsd || openbsd || netbsd +// +build freebsd openbsd netbsd + +package scoutfs + +import "syscall" + +var ( + errNoData = syscall.ENOATTR +) diff --git a/s3select/arch32.go b/s3select/arch32.go new file mode 100644 index 0000000..14fbc5c --- /dev/null +++ b/s3select/arch32.go @@ -0,0 +1,24 @@ +// Copyright 2023 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build !amd64 && !arm64 && !ppc64le && !riscv64 +// +build !amd64,!arm64,!ppc64le,!riscv64 + +package s3select + +import "math" + +const ( + maxMessageSize = math.MaxInt +) diff --git a/s3select/arch64.go b/s3select/arch64.go new file mode 100644 index 0000000..238edc6 --- /dev/null +++ b/s3select/arch64.go @@ -0,0 +1,22 @@ +// Copyright 2023 Versity Software +// This file is licensed under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build amd64 || arm64 || ppc64le || riscv64 +// +build amd64 arm64 ppc64le riscv64 + +package s3select + +const ( + maxMessageSize = 5 * 1024 * 1024 * 1024 +) diff --git a/s3select/message-handler.go b/s3select/message-handler.go index fcefc0b..0000025 100644 --- a/s3select/message-handler.go +++ b/s3select/message-handler.go @@ -123,8 +123,7 @@ func generatePrelude(msgLen int, headerLen int) []byte { } const ( - maxHeaderSize = 1024 * 1024 - maxMessageSize = 5 * 1024 * 1024 * 1024 + maxHeaderSize = 1024 * 1024 ) func genMessage(header, payload []byte) []byte {