Skip to content
Open
Show file tree
Hide file tree
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: 10 additions & 15 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@ name: Lint & Test
on:
pull_request:
workflow_call:
push:
branches:
- master

Comment thread
peterjan marked this conversation as resolved.
env:
CGO_ENABLED: 1

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Configure git
run: git config --global core.autocrlf false # required on Windows
run: git config --global core.autocrlf false
- uses: actions/checkout@v5
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version: '1.24'
- uses: golangci/golangci-lint-action@v7
with:
skip-cache: true
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Test
uses: n8maninger/action-golang-test@v2
with:
args: -race;-failfast
uses: SiaFoundation/workflows/.github/workflows/go-test.yml@master
8 changes: 2 additions & 6 deletions sia/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,9 @@ func (s *Sia) UploadPart(ctx context.Context, accessKeyID, bucket, object string
}

// sync parent directory
if dir, err := os.Open(partDir); errors.Is(err, os.ErrNotExist) {
if err := syncDir(partDir); errors.Is(err, os.ErrNotExist) {
return nil, s3errs.ErrNoSuchUpload
} else if err != nil {
return nil, fmt.Errorf("failed to open part directory: %w", err)
} else if err := errors.Join(dir.Sync(), dir.Close()); err != nil {
return nil, fmt.Errorf("failed to sync part directory: %w", err)
}

Expand Down Expand Up @@ -312,11 +310,9 @@ func (s *Sia) UploadPartCopy(ctx context.Context, accessKeyID, srcBucket, srcObj
}

// sync parent directory
if dir, err := os.Open(partDir); errors.Is(err, os.ErrNotExist) {
if err := syncDir(partDir); errors.Is(err, os.ErrNotExist) {
return nil, s3errs.ErrNoSuchUpload
} else if err != nil {
return nil, fmt.Errorf("failed to open part directory: %w", err)
} else if err := errors.Join(dir.Sync(), dir.Close()); err != nil {
return nil, fmt.Errorf("failed to sync part directory: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion sia/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *Sia) openUpload(bucket, name string, obj *objects.Object, offset int64)
uploadDir := filepath.Join(s.uploadDir(), *obj.FileName)
return objects.NewReader(uploadDir, parts, offset)
}
f, err := os.Open(filepath.Join(s.uploadDir(), *obj.FileName))
f, err := openFileAllowDelete(filepath.Join(s.uploadDir(), *obj.FileName))
if err != nil {
return nil, err
}
Expand Down
20 changes: 20 additions & 0 deletions sia/os_nonwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build !windows

package sia

import (
"errors"
"os"
)

func openFileAllowDelete(path string) (*os.File, error) {
return os.Open(path)
}

func syncDir(path string) error {
dir, err := os.Open(path)
if err != nil {
return err
}
return errors.Join(dir.Sync(), dir.Close())
}
34 changes: 34 additions & 0 deletions sia/os_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build windows

package sia

import (
"os"
"syscall"
)

func openFileAllowDelete(path string) (*os.File, error) {
p, err := syscall.UTF16PtrFromString(path)
if err != nil {
return nil, err
}

h, err := syscall.CreateFile(
p,
syscall.GENERIC_READ,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
nil,
syscall.OPEN_EXISTING,
syscall.FILE_ATTRIBUTE_NORMAL,
0,
)
if err != nil {
return nil, err
}

return os.NewFile(uintptr(h), path), nil
}

func syncDir(path string) error {
return nil
}
4 changes: 4 additions & 0 deletions sia/persist/sqlite/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func TestListObjects(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { store.Close() })
Comment thread
peterjan marked this conversation as resolved.

// prepare a bucket
bucket := "foo"
Expand Down Expand Up @@ -375,6 +376,7 @@ func TestListObjectsMatch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { store.Close() })
Comment thread
peterjan marked this conversation as resolved.

// prepare a bucket
bucket := "foo"
Expand Down Expand Up @@ -483,6 +485,7 @@ func TestListObjectsWalk(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { store.Close() })
Comment thread
peterjan marked this conversation as resolved.

// prepare a bucket
bucket := "foo"
Expand Down Expand Up @@ -579,6 +582,7 @@ func BenchmarkListObjects(b *testing.B) {
if err != nil {
b.Fatal(err)
}
b.Cleanup(func() { store.Close() })
Comment thread
peterjan marked this conversation as resolved.

// prepare a bucket
bucket := "foo"
Expand Down
Loading