webdav: open Windows Explorer when starting
This commit is contained in:
parent
ff7bfc534f
commit
7782b7c38e
1 changed files with 13 additions and 4 deletions
|
@ -5,7 +5,9 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -87,20 +89,21 @@ func init() {
|
||||||
|
|
||||||
func runWebServer(ctx context.Context, opts WebdavOptions, gopts GlobalOptions, args []string) error {
|
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 {
|
if len(args) == 0 {
|
||||||
return errors.Fatal("wrong number of parameters")
|
return errors.Fatal("wrong number of parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
bindAddress := args[0]
|
bindAddress := args[0]
|
||||||
|
|
||||||
|
// FIXME: Proper validation, also check for IPv6
|
||||||
if strings.Index(bindAddress, "http://") == 0 {
|
if strings.Index(bindAddress, "http://") == 0 {
|
||||||
bindAddress = bindAddress[7:]
|
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)
|
ctx, repo, unlock, err := openWithReadLock(ctx, gopts, gopts.NoLock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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("Tree contains %d snapshots\n", len(davFS.root.children))
|
||||||
Printf("When finished, quit with Ctrl-c here.\n")
|
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)
|
return http.ListenAndServe(bindAddress, wd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue