Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
126dfde6
Commit
126dfde6
authored
Nov 04, 2018
by
Elad
Committed by
Viktor Trón
Nov 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/swarm: auto resolve default path according to env flag (#17960)
parent
f08f596a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
config.go
cmd/swarm/config.go
+1
-0
upload.go
cmd/swarm/upload.go
+28
-10
No files found.
cmd/swarm/config.go
View file @
126dfde6
...
@@ -80,6 +80,7 @@ const (
...
@@ -80,6 +80,7 @@ const (
SWARM_ENV_STORE_CAPACITY
=
"SWARM_STORE_CAPACITY"
SWARM_ENV_STORE_CAPACITY
=
"SWARM_STORE_CAPACITY"
SWARM_ENV_STORE_CACHE_CAPACITY
=
"SWARM_STORE_CACHE_CAPACITY"
SWARM_ENV_STORE_CACHE_CAPACITY
=
"SWARM_STORE_CACHE_CAPACITY"
SWARM_ACCESS_PASSWORD
=
"SWARM_ACCESS_PASSWORD"
SWARM_ACCESS_PASSWORD
=
"SWARM_ACCESS_PASSWORD"
SWARM_AUTO_DEFAULTPATH
=
"SWARM_AUTO_DEFAULTPATH"
GETH_ENV_DATADIR
=
"GETH_DATADIR"
GETH_ENV_DATADIR
=
"GETH_DATADIR"
)
)
...
...
cmd/swarm/upload.go
View file @
126dfde6
...
@@ -26,8 +26,10 @@ import (
...
@@ -26,8 +26,10 @@ import (
"os/user"
"os/user"
"path"
"path"
"path/filepath"
"path/filepath"
"strconv"
"strings"
"strings"
"github.com/ethereum/go-ethereum/log"
swarm
"github.com/ethereum/go-ethereum/swarm/api/client"
swarm
"github.com/ethereum/go-ethereum/swarm/api/client"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/cmd/utils"
...
@@ -47,17 +49,24 @@ var upCommand = cli.Command{
...
@@ -47,17 +49,24 @@ var upCommand = cli.Command{
func
upload
(
ctx
*
cli
.
Context
)
{
func
upload
(
ctx
*
cli
.
Context
)
{
args
:=
ctx
.
Args
()
args
:=
ctx
.
Args
()
var
(
var
(
bzzapi
=
strings
.
TrimRight
(
ctx
.
GlobalString
(
SwarmApiFlag
.
Name
),
"/"
)
bzzapi
=
strings
.
TrimRight
(
ctx
.
GlobalString
(
SwarmApiFlag
.
Name
),
"/"
)
recursive
=
ctx
.
GlobalBool
(
SwarmRecursiveFlag
.
Name
)
recursive
=
ctx
.
GlobalBool
(
SwarmRecursiveFlag
.
Name
)
wantManifest
=
ctx
.
GlobalBoolT
(
SwarmWantManifestFlag
.
Name
)
wantManifest
=
ctx
.
GlobalBoolT
(
SwarmWantManifestFlag
.
Name
)
defaultPath
=
ctx
.
GlobalString
(
SwarmUploadDefaultPath
.
Name
)
defaultPath
=
ctx
.
GlobalString
(
SwarmUploadDefaultPath
.
Name
)
fromStdin
=
ctx
.
GlobalBool
(
SwarmUpFromStdinFlag
.
Name
)
fromStdin
=
ctx
.
GlobalBool
(
SwarmUpFromStdinFlag
.
Name
)
mimeType
=
ctx
.
GlobalString
(
SwarmUploadMimeType
.
Name
)
mimeType
=
ctx
.
GlobalString
(
SwarmUploadMimeType
.
Name
)
client
=
swarm
.
NewClient
(
bzzapi
)
client
=
swarm
.
NewClient
(
bzzapi
)
toEncrypt
=
ctx
.
Bool
(
SwarmEncryptedFlag
.
Name
)
toEncrypt
=
ctx
.
Bool
(
SwarmEncryptedFlag
.
Name
)
file
string
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
len
(
args
)
!=
1
{
if
fromStdin
{
if
fromStdin
{
tmp
,
err
:=
ioutil
.
TempFile
(
""
,
"swarm-stdin"
)
tmp
,
err
:=
ioutil
.
TempFile
(
""
,
"swarm-stdin"
)
...
@@ -106,6 +115,15 @@ func upload(ctx *cli.Context) {
...
@@ -106,6 +115,15 @@ func upload(ctx *cli.Context) {
if
!
recursive
{
if
!
recursive
{
return
""
,
errors
.
New
(
"Argument is a directory and recursive upload is disabled"
)
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
!=
""
{
if
defaultPath
!=
""
{
// construct absolute default path
// construct absolute default path
absDefaultPath
,
_
:=
filepath
.
Abs
(
defaultPath
)
absDefaultPath
,
_
:=
filepath
.
Abs
(
defaultPath
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment