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