Build on several platforms (#13)
- Added a GitHub workflow to compile distribyted on linux, macOS and windows. - Fixed some problems on storage when running on windows. - Added more documentation about how to use on windows. - Now on every build, artifacts are generated and can be downloaded for testing before a release. - Only cross-compiling arm-7 for now. Fixes #6 Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
parent
21f4a5f1da
commit
1614af438e
8 changed files with 170 additions and 97 deletions
|
@ -3,10 +3,11 @@ package fs
|
|||
import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const separator = "/"
|
||||
|
||||
type FsFactory func(f File) (Filesystem, error)
|
||||
|
||||
var SupportedFactories = map[string]FsFactory{
|
||||
|
@ -76,8 +77,8 @@ func (s *storage) Add(f File, p string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *storage) createParent(path string, f File) error {
|
||||
base, filename := filepath.Split(path)
|
||||
func (s *storage) createParent(p string, f File) error {
|
||||
base, filename := path.Split(p)
|
||||
base = clean(base)
|
||||
|
||||
if err := s.Add(&Dir{}, base); err != nil {
|
||||
|
@ -128,7 +129,7 @@ func (s *storage) Get(path string) (File, error) {
|
|||
func (s *storage) getFileFromFs(p string) (File, error) {
|
||||
for fsp, fs := range s.filesystems {
|
||||
if strings.HasPrefix(p, fsp) {
|
||||
return fs.Open(string(os.PathSeparator) + strings.TrimPrefix(p, fsp))
|
||||
return fs.Open(separator + strings.TrimPrefix(p, fsp))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,6 +147,6 @@ func (s *storage) getDirFromFs(p string) (map[string]File, error) {
|
|||
return nil, os.ErrNotExist
|
||||
}
|
||||
|
||||
func clean(path string) string {
|
||||
return filepath.Clean(string(os.PathSeparator) + filepath.FromSlash(path))
|
||||
func clean(p string) string {
|
||||
return path.Clean(separator + strings.ReplaceAll(p, "\\", "/"))
|
||||
}
|
||||
|
|
|
@ -83,6 +83,25 @@ func TestStorage(t *testing.T) {
|
|||
require.Equal(&Dummy{}, file)
|
||||
}
|
||||
|
||||
func TestStorageWindowsPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require := require.New(t)
|
||||
|
||||
s := newStorage(dummyFactories)
|
||||
|
||||
err := s.Add(&Dummy{}, "\\path\\to\\dummy\\file.txt")
|
||||
require.NoError(err)
|
||||
|
||||
file, err := s.Get("\\path\\to\\dummy\\file.txt")
|
||||
require.NoError(err)
|
||||
require.Equal(&Dummy{}, file)
|
||||
|
||||
file, err = s.Get("/path/to/dummy/file.txt")
|
||||
require.NoError(err)
|
||||
require.Equal(&Dummy{}, file)
|
||||
}
|
||||
|
||||
var _ Filesystem = &DummyFs{}
|
||||
|
||||
type DummyFs struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue