Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

shell: expand `~` in local file path arguments (#9265)

Chris Lu294f7c3d046e
diff --git a/weed/shell/command_fs_meta_change_volume_id.go b/weed/shell/command_fs_meta_change_volume_id.go
index 2eded1afd3..ef5a9386a2 100644
--- a/weed/shell/command_fs_meta_change_volume_id.go
+++ b/weed/shell/command_fs_meta_change_volume_id.go
@@ -63,7 +63,7 @@ func (c *commandFsMetaChangeVolumeId) Do(args []string, commandEnv *CommandEnv,
// load the mapping
mapping := make(map[needle.VolumeId]needle.VolumeId)
if *mappingFileName != "" {
- readMappingFromFile(*mappingFileName, mapping)
+ readMappingFromFile(util.ResolvePath(*mappingFileName), mapping)
} else {
if *fromVolumeId == *toVolumeId {
return fmt.Errorf("no volume id changes")
diff --git a/weed/shell/command_fs_meta_load.go b/weed/shell/command_fs_meta_load.go
index 95c31ac554..93426ce516 100644
--- a/weed/shell/command_fs_meta_load.go
+++ b/weed/shell/command_fs_meta_load.go
@@ -51,7 +51,7 @@ func (c *commandFsMetaLoad) Do(args []string, commandEnv *CommandEnv, writer io.
return nil
}
- fileName := args[len(args)-1]
+ fileName := util.ResolvePath(args[len(args)-1])
metaLoadCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
c.dirPrefix = metaLoadCommand.String("dirPrefix", "", "load entries only with directories matching prefix")
diff --git a/weed/shell/command_fs_meta_save.go b/weed/shell/command_fs_meta_save.go
index 5f5388dcaa..be823611c2 100644
--- a/weed/shell/command_fs_meta_save.go
+++ b/weed/shell/command_fs_meta_save.go
@@ -68,7 +68,7 @@ func (c *commandFsMetaSave) Do(args []string, commandEnv *CommandEnv, writer io.
return parseErr
}
- fileName := *outputFileName
+ fileName := util.ResolvePath(*outputFileName)
if fileName == "" {
t := time.Now()
fileName = fmt.Sprintf("%s-%4d%02d%02d-%02d%02d%02d.meta.gz",
diff --git a/weed/shell/command_s3_iam_export.go b/weed/shell/command_s3_iam_export.go
index b0a1c6d7f8..708d59e5b4 100644
--- a/weed/shell/command_s3_iam_export.go
+++ b/weed/shell/command_s3_iam_export.go
@@ -11,6 +11,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
+ "github.com/seaweedfs/seaweedfs/weed/util"
"google.golang.org/grpc"
)
@@ -58,8 +59,9 @@ func (c *commandS3IAMExport) Do(args []string, commandEnv *CommandEnv, writer io
}
var out io.Writer = writer
- if *file != "" {
- fp, err := os.OpenFile(*file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
+ outputFile := util.ResolvePath(*file)
+ if outputFile != "" {
+ fp, err := os.OpenFile(outputFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("create file: %v", err)
}
@@ -72,8 +74,8 @@ func (c *commandS3IAMExport) Do(args []string, commandEnv *CommandEnv, writer io
}
fmt.Fprintln(out)
- if *file != "" {
- fmt.Fprintf(writer, "Exported IAM configuration to %s\n", *file)
+ if outputFile != "" {
+ fmt.Fprintf(writer, "Exported IAM configuration to %s\n", outputFile)
}
return nil
}, commandEnv.option.FilerAddress.ToGrpcAddress(), false, commandEnv.option.GrpcDialOption)
diff --git a/weed/shell/command_s3_iam_import.go b/weed/shell/command_s3_iam_import.go
index 6d4d00c9f4..9288497eb0 100644
--- a/weed/shell/command_s3_iam_import.go
+++ b/weed/shell/command_s3_iam_import.go
@@ -11,6 +11,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
+ "github.com/seaweedfs/seaweedfs/weed/util"
"google.golang.org/grpc"
)
@@ -56,7 +57,7 @@ func (c *commandS3IAMImport) Do(args []string, commandEnv *CommandEnv, writer io
return fmt.Errorf("this overwrites the entire IAM configuration; use -apply to confirm")
}
- data, err := os.ReadFile(*file)
+ data, err := os.ReadFile(util.ResolvePath(*file))
if err != nil {
return fmt.Errorf("read file: %w", err)
}
diff --git a/weed/shell/command_s3_policy.go b/weed/shell/command_s3_policy.go
index 1cd30b1879..26276e1bcf 100644
--- a/weed/shell/command_s3_policy.go
+++ b/weed/shell/command_s3_policy.go
@@ -12,6 +12,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/policy_engine"
+ "github.com/seaweedfs/seaweedfs/weed/util"
"google.golang.org/grpc"
)
@@ -86,7 +87,7 @@ func (c *commandS3Policy) Do(args []string, commandEnv *CommandEnv, writer io.Wr
if *file == "" {
return fmt.Errorf("-file is required")
}
- data, err := os.ReadFile(*file)
+ data, err := os.ReadFile(util.ResolvePath(*file))
if err != nil {
return fmt.Errorf("failed to read policy file: %v", err)
}
diff --git a/weed/shell/command_s3tables_bucket.go b/weed/shell/command_s3tables_bucket.go
index c715aebc4f..d24a80599c 100644
--- a/weed/shell/command_s3tables_bucket.go
+++ b/weed/shell/command_s3tables_bucket.go
@@ -11,6 +11,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
+ "github.com/seaweedfs/seaweedfs/weed/util"
)
func init() {
@@ -176,7 +177,7 @@ func (c *commandS3TablesBucket) Do(args []string, commandEnv *CommandEnv, writer
if *policyFile == "" {
return fmt.Errorf("-file is required")
}
- content, err := os.ReadFile(*policyFile)
+ content, err := os.ReadFile(util.ResolvePath(*policyFile))
if err != nil {
return err
}
diff --git a/weed/shell/command_s3tables_table.go b/weed/shell/command_s3tables_table.go
index 4f056dae16..f0336183de 100644
--- a/weed/shell/command_s3tables_table.go
+++ b/weed/shell/command_s3tables_table.go
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
+ "github.com/seaweedfs/seaweedfs/weed/util"
)
func init() {
@@ -108,7 +109,7 @@ func (c *commandS3TablesTable) Do(args []string, commandEnv *CommandEnv, writer
case *create:
var metadata *s3tables.TableMetadata
if *metadataFile != "" {
- content, err := os.ReadFile(*metadataFile)
+ content, err := os.ReadFile(util.ResolvePath(*metadataFile))
if err != nil {
return err
}
@@ -178,7 +179,7 @@ func (c *commandS3TablesTable) Do(args []string, commandEnv *CommandEnv, writer
if *policyFile == "" {
return fmt.Errorf("-file is required")
}
- content, err := os.ReadFile(*policyFile)
+ content, err := os.ReadFile(util.ResolvePath(*policyFile))
if err != nil {
return err
}
diff --git a/weed/shell/command_volume_fsck.go b/weed/shell/command_volume_fsck.go
index c74c6033d3..d86b2ebf4d 100644
--- a/weed/shell/command_volume_fsck.go
+++ b/weed/shell/command_volume_fsck.go
@@ -145,7 +145,7 @@ func (c *commandVolumeFsck) Do(args []string, commandEnv *CommandEnv, writer io.
}
// create a temp folder
- c.tempFolder, err = os.MkdirTemp(*tempPath, "sw_fsck")
+ c.tempFolder, err = os.MkdirTemp(util.ResolvePath(*tempPath), "sw_fsck")
if err != nil {
return fmt.Errorf("failed to create temp folder: %w", err)
}