webdav: open Windows Explorer when starting

This commit is contained in:
Alex Duchesne 2024-04-06 10:23:59 -04:00
parent ff7bfc534f
commit 7782b7c38e
1 changed files with 13 additions and 4 deletions

View File

@ -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)
}