func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) { r := n.Repo usage, err := r.GetStorageUsage() if err != nil { return nil, err } allKeys, err := n.Blockstore.AllKeysChan(ctx) if err != nil { return nil, err } count := uint64(0) for range allKeys { count++ } path, err := fsrepo.BestKnownPath() if err != nil { return nil, err } return &Stat{ NumObjects: count, RepoSize: usage, RepoPath: path, }, nil }
func getRepoPath() (string, error) { repoPath, err := fsrepo.BestKnownPath() if err != nil { return "", err } return repoPath, nil }
func getRepoPath(req cmds.Request) (string, error) { repoOpt, found, err := req.Option("config").String() if err != nil { return "", err } if found && repoOpt != "" { return repoOpt, nil } repoPath, err := fsrepo.BestKnownPath() if err != nil { return "", err } return repoPath, nil }
func main() { bkp, err := fsrepo.BestKnownPath() if err != nil { panic(err) } r, err := fsrepo.Open(bkp) if err != nil { panic(err) } k := ds.NewKey(os.Args[1]) val, err := r.Datastore().Get(k) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } fmt.Println(string(val.([]byte))) }
func main() { flag.Parse() // precedence // 1. --repo flag // 2. IPFS_PATH environment variable // 3. default repo path var ipfsPath string if *repoPath != "" { ipfsPath = *repoPath } else { var err error ipfsPath, err = fsrepo.BestKnownPath() if err != nil { log.Fatal(err) } } if err := run(ipfsPath, *watchPath); err != nil { log.Fatal(err) } }