From 7782b7c38ebaf0a24e83b9b64297df189d150d42 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sat, 6 Apr 2024 10:23:59 -0400 Subject: [PATCH] webdav: open Windows Explorer when starting --- cmd/restic/cmd_webdav.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_webdav.go b/cmd/restic/cmd_webdav.go index 7628a2be5..bca6858f9 100644 --- a/cmd/restic/cmd_webdav.go +++ b/cmd/restic/cmd_webdav.go @@ -5,7 +5,9 @@ import ( "io" "net/http" "os" + "os/exec" "path" + "runtime" "sort" "strings" "time" @@ -87,20 +89,21 @@ func init() { func runWebServer(ctx context.Context, opts WebdavOptions, gopts GlobalOptions, args []string) error { + // PathTemplates and TimeTemplate are ignored for now because `fuse.snapshots_dir(struct)` + // is not accessible when building on Windows and it would be ridiculous to duplicate the + // code. It should be shared, somehow. + if len(args) == 0 { return errors.Fatal("wrong number of parameters") } bindAddress := args[0] + // FIXME: Proper validation, also check for IPv6 if strings.Index(bindAddress, "http://") == 0 { bindAddress = bindAddress[7:] } - // PathTemplates and TimeTemplate are ignored for now because `fuse.snapshots_dir(struct)` - // is not accessible when building on Windows and it would be ridiculous to duplicate the - // code. It should be shared, somehow. - ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock) if err != nil { return err @@ -150,6 +153,12 @@ func runWebServer(ctx context.Context, opts WebdavOptions, gopts GlobalOptions, Printf("Tree contains %d snapshots\n", len(davFS.root.children)) Printf("When finished, quit with Ctrl-c here.\n") + // FIXME: Remove before PR, this is handy for testing but likely undesirable :) + if runtime.GOOS == "windows" { + browseURL := "\\\\" + strings.Replace(bindAddress, ":", "@", 1) + "\\DavWWWRoot" + exec.Command("explorer", browseURL).Start() + } + return http.ListenAndServe(bindAddress, wd) }