Commit 80c64ffa authored by Jeromy's avatar Jeromy

break ipns into separate files

parent 41bc355b
package ipns
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"time"
"bytes"
......@@ -469,130 +464,3 @@ func (n *Node) Rename(req *fuse.RenameRequest, newDir fs.Node, intr fs.Intr) fus
}
return nil
}
// Mount mounts an IpfsNode instance at a particular path. It
// serves until the process receives exit signals (to Unmount).
func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT,
syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-sigc
for {
err := Unmount(fpath)
if err == nil {
return
}
time.Sleep(time.Millisecond * 100)
}
ipfs.Network.Close()
}()
c, err := fuse.Mount(fpath)
if err != nil {
return err
}
defer c.Close()
fsys, err := NewIpns(ipfs, ipfspath)
if err != nil {
return err
}
err = fs.Serve(c, fsys)
if err != nil {
return err
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
return err
}
return nil
}
// Unmount attempts to unmount the provided FUSE mount point, forcibly
// if necessary.
func Unmount(point string) error {
fmt.Printf("Unmounting %s...\n", point)
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("diskutil", "umount", "force", point)
case "linux":
cmd = exec.Command("fusermount", "-u", point)
default:
return fmt.Errorf("unmount: unimplemented")
}
errc := make(chan error, 1)
go func() {
if err := exec.Command("umount", point).Run(); err == nil {
errc <- err
}
// retry to unmount with the fallback cmd
errc <- cmd.Run()
}()
select {
case <-time.After(1 * time.Second):
return fmt.Errorf("umount timeout")
case err := <-errc:
return err
}
}
type Link struct {
Target string
}
func (l *Link) Attr() fuse.Attr {
log.Debug("Link attr.")
return fuse.Attr{
Mode: os.ModeSymlink | 0555,
}
}
func (l *Link) Readlink(req *fuse.ReadlinkRequest, intr fs.Intr) (string, fuse.Error) {
log.Debug("ReadLink: %s", l.Target)
return l.Target, nil
}
type Republisher struct {
Timeout time.Duration
Publish chan struct{}
node *Node
}
func NewRepublisher(n *Node, tout time.Duration) *Republisher {
return &Republisher{
Timeout: tout,
Publish: make(chan struct{}),
node: n,
}
}
func (np *Republisher) Run() {
for _ = range np.Publish {
timer := time.After(np.Timeout)
for {
select {
case <-timer:
//Do the publish!
log.Info("Publishing Changes!")
err := np.node.updateTree()
if err != nil {
log.Critical("updateTree error: %s", err)
}
goto done
case <-np.Publish:
timer = time.After(np.Timeout)
}
}
done:
}
}
package ipns
import (
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
)
type Link struct {
Target string
}
func (l *Link) Attr() fuse.Attr {
log.Debug("Link attr.")
return fuse.Attr{
Mode: os.ModeSymlink | 0555,
}
}
func (l *Link) Readlink(req *fuse.ReadlinkRequest, intr fs.Intr) (string, fuse.Error) {
log.Debug("ReadLink: %s", l.Target)
return l.Target, nil
}
package ipns
import (
"fmt"
"os"
"os/exec"
"os/signal"
"runtime"
"syscall"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
"github.com/jbenet/go-ipfs/core"
)
// Mount mounts an IpfsNode instance at a particular path. It
// serves until the process receives exit signals (to Unmount).
func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGHUP, syscall.SIGINT,
syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-sigc
for {
err := Unmount(fpath)
if err == nil {
return
}
time.Sleep(time.Millisecond * 100)
}
ipfs.Network.Close()
}()
c, err := fuse.Mount(fpath)
if err != nil {
return err
}
defer c.Close()
fsys, err := NewIpns(ipfs, ipfspath)
if err != nil {
return err
}
err = fs.Serve(c, fsys)
if err != nil {
return err
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
return err
}
return nil
}
// Unmount attempts to unmount the provided FUSE mount point, forcibly
// if necessary.
func Unmount(point string) error {
fmt.Printf("Unmounting %s...\n", point)
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("diskutil", "umount", "force", point)
case "linux":
cmd = exec.Command("fusermount", "-u", point)
default:
return fmt.Errorf("unmount: unimplemented")
}
errc := make(chan error, 1)
go func() {
if err := exec.Command("umount", point).Run(); err == nil {
errc <- err
}
// retry to unmount with the fallback cmd
errc <- cmd.Run()
}()
select {
case <-time.After(1 * time.Second):
return fmt.Errorf("umount timeout")
case err := <-errc:
return err
}
}
package ipns
import "time"
type Republisher struct {
Timeout time.Duration
Publish chan struct{}
node *Node
}
func NewRepublisher(n *Node, tout time.Duration) *Republisher {
return &Republisher{
Timeout: tout,
Publish: make(chan struct{}),
node: n,
}
}
func (np *Republisher) Run() {
for _ = range np.Publish {
timer := time.After(np.Timeout)
for {
select {
case <-timer:
//Do the publish!
log.Info("Publishing Changes!")
err := np.node.updateTree()
if err != nil {
log.Critical("updateTree error: %s", err)
}
goto done
case <-np.Publish:
timer = time.After(np.Timeout)
}
}
done:
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment