Skip to content

Commit d419444

Browse files
load remote configuration from flags and setup the fuse fs
1 parent 9e72261 commit d419444

File tree

13 files changed

+118
-95
lines changed

13 files changed

+118
-95
lines changed

commands.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func getOwnCommands() []ownCommand {
165165
needConfiguration: true,
166166
noProfile: true,
167167
hide: true,
168+
experimental: true,
168169
},
169170
{
170171
name: "serve",
@@ -173,14 +174,7 @@ func getOwnCommands() []ownCommand {
173174
needConfiguration: true,
174175
noProfile: true,
175176
hide: true,
176-
},
177-
{
178-
name: "mount-config",
179-
description: "mount virtual filesystem from remote configuration files",
180-
action: mountConfigCommand,
181-
needConfiguration: false,
182-
noProfile: true,
183-
hide: true,
177+
experimental: true,
184178
},
185179
}
186180
}

constants/exit_code.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package constants
2+
3+
const (
4+
ExitSuccess = iota
5+
ExitGeneralError
6+
ExitErrorInvalidFlags
7+
ExitRunningOnBattery
8+
ExitCannotSetupRemoteConfiguration
9+
ExitErrorChildHasNoParentPort = 10
10+
)

examples/linux.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ self:
7979
backup:
8080
extended-status: true
8181
source: ./
82+
exclude-file:
83+
- root-excludes
84+
- excludes
8285
copy:
8386
initialize: true
8487
schedule-permission: user
8588
schedule:
86-
- "*:45"
89+
- "*:45"
8790

8891
src:
8992
inherit: default
@@ -92,18 +95,18 @@ src:
9295
backup:
9396
check-before: true
9497
exclude:
95-
- /**/.git
98+
- /**/.git
9699
exclude-caches: true
97100
one-file-system: false
98101
run-after: echo All Done!
99102
run-before:
100-
- echo Starting!
101-
- ls -al ~/go
103+
- echo Starting!
104+
- ls -al ~/go
102105
source:
103-
- ~/go
106+
- ~/go
104107
tag:
105-
- test
106-
- dev
108+
- test
109+
- dev
107110
retention:
108111
after-backup: true
109112
before-backup: false
@@ -112,8 +115,8 @@ src:
112115
prune: true
113116
snapshots:
114117
tag:
115-
- test
116-
- dev
118+
- test
119+
- dev
117120

118121
stdin:
119122
inherit: default

fuse/memfs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//go:build !windows
22

3-
// Simple implementation of a read-only filesystem in memory from a TAR file.
4-
// We don't want any file from the TAR to be saved on the disk
3+
// Simple implementation of a read-only filesystem in memory.
54
//
65
// Based on the examples at https://pkg.go.dev/github.com/hanwen/go-fuse/v2/fs#pkg-examples
76
package fuse

fuse/memfs_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/hanwen/go-fuse/v2/fs"
14-
"github.com/hanwen/go-fuse/v2/fuse"
1513
"github.com/stretchr/testify/assert"
1614
"github.com/stretchr/testify/require"
1715
)
@@ -50,20 +48,13 @@ func TestMemFS(t *testing.T) {
5048
})
5149
}
5250

53-
memFS := newMemFS(files)
54-
5551
mnt := t.TempDir()
56-
opts := &fs.Options{
57-
MountOptions: fuse.MountOptions{
58-
Debug: false, // generates a LOT of logs
59-
},
60-
}
61-
server, err := fs.Mount(mnt, memFS, opts)
52+
closeMount, err := MountFS(mnt, files)
6253
if err != nil && strings.Contains(err.Error(), "no FUSE mount utility found") {
6354
t.Skip("no FUSE mount utility found")
6455
}
6556
require.NoError(t, err, "cannot mount FS")
66-
defer server.Unmount()
57+
defer closeMount()
6758

6859
for filename, fileContents := range memfsContents {
6960
fullPath := filepath.Join(mnt, filename)

fuse/memfs_windows_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build windows
2+
3+
package fuse
4+
5+
import (
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestMountFS(t *testing.T) {
12+
_, err := MountFS("mnt", []File{})
13+
assert.Error(t, err)
14+
}

fuse/mount.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@ package fuse
44

55
import (
66
"fmt"
7-
"math/rand"
8-
"os"
9-
"path/filepath"
107

118
"github.com/creativeprojects/clog"
129
"github.com/hanwen/go-fuse/v2/fs"
1310
"github.com/hanwen/go-fuse/v2/fuse"
1411
)
1512

16-
func MountFS(files []File) (func(), error) {
13+
func MountFS(mountpoint string, files []File) (func(), error) {
1714
memFS := newMemFS(files)
1815

19-
mountpoint := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%x", "resticprofile", rand.Uint32()))
20-
err := os.MkdirAll(mountpoint, 0o755)
21-
if err != nil {
22-
return nil, fmt.Errorf("failed to create mount directory: %w", err)
23-
}
2416
clog.Debugf("mounting filesystem at %s", mountpoint)
2517

2618
opts := &fs.Options{
@@ -36,14 +28,12 @@ func MountFS(files []File) (func(), error) {
3628
return nil, fmt.Errorf("failed to mount filesystem: %w", err)
3729
}
3830
close := func() {
39-
err := server.Unmount()
31+
clog.Debug("unmounting filesystem")
32+
err := server.Unmount() // don't need to call Wait after Unmount
4033
if err != nil {
4134
clog.Errorf("failed to unmount filesystem: %v", err)
4235
}
43-
err = os.Remove(mountpoint)
44-
if err != nil {
45-
clog.Errorf("failed to remove mountpoint: %v", err)
46-
}
36+
4737
memFS.Close()
4838
}
4939
return close, nil

fuse/mount_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package fuse
22

33
import "errors"
44

5-
func MountFS(files []File) (func(), error) {
5+
func MountFS(_ string, _ []File) (func(), error) {
66
return nil, errors.New("not supported on Windows")
77
}

main.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ func main() {
142142

143143
banner()
144144

145+
if flags.remote != "" {
146+
closeFS, err := setupRemoteConfiguration(flags.remote)
147+
if err != nil {
148+
// need to setup console logging to display the error message
149+
closeLogger := setupLogging(nil)
150+
defer closeLogger()
151+
clog.Error(err)
152+
exitCode = constants.ExitCannotSetupRemoteConfiguration
153+
return
154+
}
155+
shutdown.AddHook(closeFS)
156+
}
157+
145158
// resticprofile own commands (configuration file may not be loaded)
146159
if len(flags.resticArgs) > 0 {
147160
if ownCommands.Exists(flags.resticArgs[0], false) {
@@ -280,21 +293,22 @@ func banner() {
280293
func loadConfig(flags commandLineFlags, silent bool) (cfg *config.Config, global *config.Global, err error) {
281294
fs := afero.NewOsFs()
282295

283-
if flags.remote != "" {
284-
// fs = afero.NewMemMapFs()
285-
// parameters, err := loadRemoteConfiguration(fs, flags.remote)
286-
_, parameters, err := loadRemoteFiles(flags.remote)
287-
if err != nil {
288-
return nil, nil, fmt.Errorf("cannot load remote configuration: %w", err)
289-
}
290-
// we should probably move this to the context (and keep flags intact)
291-
if flags.config == constants.DefaultConfigurationFile {
292-
flags.config = parameters.ConfigurationFile
293-
}
294-
if flags.name == constants.DefaultProfileName {
295-
flags.name = parameters.ProfileName
296-
}
297-
}
296+
// if flags.remote != "" {
297+
// // fs = afero.NewMemMapFs()
298+
// // parameters, err := loadRemoteConfiguration(fs, flags.remote)
299+
// os.Chdir()
300+
// _, parameters, err := loadRemoteFiles(flags.remote)
301+
// if err != nil {
302+
// return nil, nil, fmt.Errorf("cannot load remote configuration: %w", err)
303+
// }
304+
// // we should probably move this to the context (and keep flags intact)
305+
// if flags.config == constants.DefaultConfigurationFile {
306+
// flags.config = parameters.ConfigurationFile
307+
// }
308+
// if flags.name == constants.DefaultProfileName {
309+
// flags.name = parameters.ProfileName
310+
// }
311+
// }
298312

299313
var configFile string
300314
if configFile, err = filesearch.FindConfigurationFile(fs, flags.config); err == nil {

mount_config.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)