-
Notifications
You must be signed in to change notification settings - Fork 8
/
filesystem.go
52 lines (43 loc) · 1.07 KB
/
filesystem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package filesystem
import (
"errors"
"os"
"github.com/spf13/afero"
"github.com/ARM-software/golang-utils/utils/commonerrors"
)
const (
StandardFS int = iota
InMemoryFS
)
var (
FileSystemTypes = []int{StandardFS, InMemoryFS}
)
func NewInMemoryFileSystem() FS {
return NewVirtualFileSystem(afero.NewMemMapFs(), InMemoryFS, IdentityPathConverterFunc)
}
func NewStandardFileSystem() FS {
return NewVirtualFileSystem(NewExtendedOsFs(), StandardFS, IdentityPathConverterFunc)
}
func NewFs(fsType int) FS {
switch fsType {
case StandardFS:
return NewStandardFileSystem()
case InMemoryFS:
return NewInMemoryFileSystem()
}
return NewStandardFileSystem()
}
// Converts file system error into common errors
func ConvertFileSytemError(err error) error {
if err == nil {
return nil
}
if commonerrors.Any(err, os.ErrExist, errors.New("file exists"), errors.New("file already exists")) {
return commonerrors.ErrExists
}
return err
}