• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cinode / go / 15633973488

13 Jun 2025 11:57AM UTC coverage: 95.318%. Remained the same
15633973488

Pull #45

github

byo
fixup
Pull Request #45: Fix github action issues

3013 of 3161 relevant lines covered (95.32%)

1.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.83
/pkg/datastore/storage_raw_filesystem.go
1
/*
2
Copyright © 2023 Bartłomiej Święcki (byo)
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package datastore
18

19
import (
20
        "context"
21
        "fmt"
22
        "io"
23
        "os"
24
        "path/filepath"
25
        "sync/atomic"
26

27
        "github.com/cinode/go/pkg/common"
28
)
29

30
type rawFileSystem struct {
31
        path        string
32
        tempFileNum uint64
33
}
34

35
var _ storage = (*rawFileSystem)(nil)
36

37
func newStorageRawFilesystem(path string) (*rawFileSystem, error) {
1✔
38
        err := os.MkdirAll(path, 0755)
1✔
39
        if err != nil {
2✔
40
                return nil, err
1✔
41
        }
1✔
42
        return &rawFileSystem{path: path}, nil
1✔
43
}
44

45
func (fs *rawFileSystem) kind() string {
1✔
46
        return "RawFileSystem"
1✔
47
}
1✔
48

49
func (fs *rawFileSystem) address() string {
1✔
50
        return rawFilePrefix + fs.path
1✔
51
}
1✔
52

53
func (fs *rawFileSystem) openReadStream(ctx context.Context, name *common.BlobName) (io.ReadCloser, error) {
1✔
54
        rc, err := os.Open(filepath.Join(fs.path, name.String()))
1✔
55
        if os.IsNotExist(err) {
2✔
56
                return nil, ErrNotFound
1✔
57
        }
1✔
58
        return rc, err
1✔
59
}
60

61
type rawFilesystemWriter struct {
62
        file         *os.File
63
        destFileName string
64
}
65

66
func (w *rawFilesystemWriter) Write(b []byte) (int, error) {
1✔
67
        return w.file.Write(b)
1✔
68
}
1✔
69

70
func (w *rawFilesystemWriter) Close() error {
1✔
71
        err := w.file.Close()
1✔
72
        if err != nil {
1✔
73
                return err
×
74
        }
×
75

76
        return os.Rename(w.file.Name(), w.destFileName)
1✔
77
}
78

79
func (w *rawFilesystemWriter) Cancel() {
1✔
80
        w.file.Close()
1✔
81
        os.Remove(w.file.Name())
1✔
82
}
1✔
83

84
func (fs *rawFileSystem) openWriteStream(ctx context.Context, name *common.BlobName) (WriteCloseCanceller, error) {
1✔
85
        tempNum := atomic.AddUint64(&fs.tempFileNum, 1)
1✔
86

1✔
87
        tempFileName := filepath.Join(fs.path, fmt.Sprintf("tempfile_%d", tempNum))
1✔
88

1✔
89
        fl, err := os.Create(tempFileName)
1✔
90
        if err != nil {
1✔
91
                return nil, err
×
92
        }
×
93

94
        return &rawFilesystemWriter{
1✔
95
                file:         fl,
1✔
96
                destFileName: filepath.Join(fs.path, name.String()),
1✔
97
        }, nil
1✔
98
}
99

100
func (fs *rawFileSystem) exists(ctx context.Context, name *common.BlobName) (bool, error) {
1✔
101
        _, err := os.Stat(filepath.Join(fs.path, name.String()))
1✔
102
        if os.IsNotExist(err) {
2✔
103
                return false, nil
1✔
104
        }
1✔
105
        if err != nil {
1✔
106
                return false, err
×
107
        }
×
108
        return true, nil
1✔
109
}
110

111
func (fs *rawFileSystem) delete(ctx context.Context, name *common.BlobName) error {
1✔
112
        err := os.Remove(filepath.Join(fs.path, name.String()))
1✔
113
        if os.IsNotExist(err) {
2✔
114
                return ErrNotFound
1✔
115
        }
1✔
116
        return err
1✔
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc