aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorElad <theman@elad.im>2018-11-04 14:59:58 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2018-11-04 14:59:58 +0800
commit126dfde6c9de1f8122bb3991453d2429b47542f8 (patch)
treea5f1f9253b0725e68c6f23fd1161988ec3f884af /cmd
parentf08f596a378e1bc0cfcb476868767b1f1d602c17 (diff)
downloaddexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar.gz
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar.bz2
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar.lz
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar.xz
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.tar.zst
dexon-126dfde6c9de1f8122bb3991453d2429b47542f8.zip
cmd/swarm: auto resolve default path according to env flag (#17960)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/swarm/config.go1
-rw-r--r--cmd/swarm/upload.go38
2 files changed, 29 insertions, 10 deletions
diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go
index 16001010d..3eea3057b 100644
--- a/cmd/swarm/config.go
+++ b/cmd/swarm/config.go
@@ -80,6 +80,7 @@ const (
SWARM_ENV_STORE_CAPACITY = "SWARM_STORE_CAPACITY"
SWARM_ENV_STORE_CACHE_CAPACITY = "SWARM_STORE_CACHE_CAPACITY"
SWARM_ACCESS_PASSWORD = "SWARM_ACCESS_PASSWORD"
+ SWARM_AUTO_DEFAULTPATH = "SWARM_AUTO_DEFAULTPATH"
GETH_ENV_DATADIR = "GETH_DATADIR"
)
diff --git a/cmd/swarm/upload.go b/cmd/swarm/upload.go
index 0dbe896e2..992f2d6e9 100644
--- a/cmd/swarm/upload.go
+++ b/cmd/swarm/upload.go
@@ -26,8 +26,10 @@ import (
"os/user"
"path"
"path/filepath"
+ "strconv"
"strings"
+ "github.com/ethereum/go-ethereum/log"
swarm "github.com/ethereum/go-ethereum/swarm/api/client"
"github.com/ethereum/go-ethereum/cmd/utils"
@@ -47,17 +49,24 @@ var upCommand = cli.Command{
func upload(ctx *cli.Context) {
args := ctx.Args()
var (
- bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
- recursive = ctx.GlobalBool(SwarmRecursiveFlag.Name)
- wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
- defaultPath = ctx.GlobalString(SwarmUploadDefaultPath.Name)
- fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name)
- mimeType = ctx.GlobalString(SwarmUploadMimeType.Name)
- client = swarm.NewClient(bzzapi)
- toEncrypt = ctx.Bool(SwarmEncryptedFlag.Name)
- file string
+ bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
+ recursive = ctx.GlobalBool(SwarmRecursiveFlag.Name)
+ wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
+ defaultPath = ctx.GlobalString(SwarmUploadDefaultPath.Name)
+ fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name)
+ mimeType = ctx.GlobalString(SwarmUploadMimeType.Name)
+ client = swarm.NewClient(bzzapi)
+ toEncrypt = ctx.Bool(SwarmEncryptedFlag.Name)
+ autoDefaultPath = false
+ file string
)
-
+ if autoDefaultPathString := os.Getenv(SWARM_AUTO_DEFAULTPATH); autoDefaultPathString != "" {
+ b, err := strconv.ParseBool(autoDefaultPathString)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_AUTO_DEFAULTPATH, err)
+ }
+ autoDefaultPath = b
+ }
if len(args) != 1 {
if fromStdin {
tmp, err := ioutil.TempFile("", "swarm-stdin")
@@ -106,6 +115,15 @@ func upload(ctx *cli.Context) {
if !recursive {
return "", errors.New("Argument is a directory and recursive upload is disabled")
}
+ if autoDefaultPath && defaultPath == "" {
+ defaultEntryCandidate := path.Join(file, "index.html")
+ log.Debug("trying to find default path", "path", defaultEntryCandidate)
+ defaultEntryStat, err := os.Stat(defaultEntryCandidate)
+ if err == nil && !defaultEntryStat.IsDir() {
+ log.Debug("setting auto detected default path", "path", defaultEntryCandidate)
+ defaultPath = defaultEntryCandidate
+ }
+ }
if defaultPath != "" {
// construct absolute default path
absDefaultPath, _ := filepath.Abs(defaultPath)