LP- Better repo handling
This commit is contained in:
parent
daebec76bf
commit
1ff0d61adb
@ -2,15 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/filecoin-project/go-statestore"
|
|
||||||
ds "github.com/ipfs/go-datastore"
|
|
||||||
dssync "github.com/ipfs/go-datastore/sync"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-statestore"
|
||||||
|
ds "github.com/ipfs/go-datastore"
|
||||||
|
dssync "github.com/ipfs/go-datastore/sync"
|
||||||
|
|
||||||
"github.com/gin-contrib/pprof"
|
"github.com/gin-contrib/pprof"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -79,12 +80,12 @@ var runCmd = &cli.Command{
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "storage-json",
|
Name: "storage-json",
|
||||||
Usage: "path to json file containing storage config",
|
Usage: "path to json file containing storage config",
|
||||||
Value: "~/.lotus/storage.json",
|
Value: "~/.lotus-provider/storage.json",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "journal",
|
Name: "journal",
|
||||||
Usage: "path to journal files",
|
Usage: "path to journal files",
|
||||||
Value: "~/.lotus/",
|
Value: "~/.lotus-provider/",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) (err error) {
|
Action: func(cctx *cli.Context) (err error) {
|
||||||
|
@ -2,8 +2,11 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -36,14 +39,31 @@ func StorageFromReader(reader io.Reader) (*storiface.StorageConfig, error) {
|
|||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteStorageFile(path string, config storiface.StorageConfig) error {
|
func WriteStorageFile(filePath string, config storiface.StorageConfig) error {
|
||||||
b, err := json.MarshalIndent(config, "", " ")
|
b, err := json.MarshalIndent(config, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("marshaling storage config: %w", err)
|
return xerrors.Errorf("marshaling storage config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(path, b, 0644); err != nil {
|
info, err := os.Stat(filePath)
|
||||||
return xerrors.Errorf("persisting storage config (%s): %w", path, err)
|
if err != nil {
|
||||||
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return xerrors.Errorf("statting storage config (%s): %w", filePath, err)
|
||||||
|
}
|
||||||
|
if path.Base(filePath) == "." {
|
||||||
|
filePath = path.Join(filePath, "storage.json")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if info.IsDir() || path.Base(filePath) == "." {
|
||||||
|
filePath = path.Join(filePath, "storage.json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.MkdirAll(path.Dir(filePath), 0755); err != nil {
|
||||||
|
return xerrors.Errorf("making storage config parent directory: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filePath, b, 0644); err != nil {
|
||||||
|
return xerrors.Errorf("persisting storage config (%s): %w", filePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user