Skip to content

Commit

Permalink
Notify the kernel of node updates
Browse files Browse the repository at this point in the history
This invalidates kernel cache for the node path.

This commit also:
* Rename childs -> children
* Remove persistent nodes
* Fix async updates
* Don't use time in inode computation for directories
  • Loading branch information
gregdel committed Oct 7, 2024
1 parent 4f840ea commit 0b3352e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 118 deletions.
26 changes: 20 additions & 6 deletions cmd/polochonfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
logger "log"
"os"
"os/signal"
"sync"
"syscall"
"time"

Expand All @@ -24,6 +25,7 @@ var (
type polochonfs struct {
fuseDebug bool
ctx context.Context
wg sync.WaitGroup

root *node

Expand All @@ -47,10 +49,12 @@ func (pfs *polochonfs) init() error {
{value: polochonToken, errMsg: "missing token"},
} {
if field.value == "" {
return fmt.Errorf(field.errMsg)
return fmt.Errorf("%s", field.errMsg)
}
}

pfs.wg = sync.WaitGroup{}

var err error
pfs.client, err = papi.New(polochonURL)
if err != nil {
Expand All @@ -62,19 +66,27 @@ func (pfs *polochonfs) init() error {
return nil
}

func (pfs *polochonfs) wait() {
pfs.wg.Wait()
}

func (pfs *polochonfs) buildFS(_ context.Context) {
log.Debug("Adding persistent nodes")
pfs.root.addChild(newPersistentNodeDir(movieDirName))
pfs.root.addChild(newPersistentNodeDir(showDirName))
pfs.root.addChild(newNodeDir(movieDirName, movieDirName, pfs.root.times))
pfs.root.addChild(newNodeDir(showDirName, showDirName, pfs.root.times))

pfs.updateMovies()
pfs.updateShows()
go pfs.handleUpdates()
}

func (pfs *polochonfs) handleUpdates() {
pfs.wg.Add(1)
defer pfs.wg.Done()

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGUSR1, syscall.SIGUSR2)

pfs.updateMovies()
pfs.updateShows()

ticker := time.NewTicker(libraryRefresh)
defer ticker.Stop()

Expand All @@ -84,9 +96,11 @@ func (pfs *polochonfs) handleUpdates() {
switch s {
case syscall.SIGUSR1:
log.Info("Updating movies from signal")
ticker.Reset(libraryRefresh)
pfs.updateMovies()
case syscall.SIGUSR2:
log.Info("Updating shows from signal")
ticker.Reset(libraryRefresh)
pfs.updateShows()
}
case <-ticker.C:
Expand Down
11 changes: 2 additions & 9 deletions cmd/polochonfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os/signal"
"os/user"
"strconv"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -114,20 +113,14 @@ func run() error {
return err
}

wg := sync.WaitGroup{}
go func() {
wg.Add(1)
defer wg.Done()
pfs.handleUpdates()
}()

log.Info("FUSE daemon started")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
cancel()

wg.Wait()
pfs.wait()

pfs.unmount(server)
return nil
}
12 changes: 8 additions & 4 deletions cmd/polochonfs/movies.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ func movieDirTitle(m *papi.Movie) string {
func (pfs *polochonfs) updateMovies() {
dir := pfs.root.getChild(movieDirName)

defer func() {
pfs.root.addChild(dir)
_ = pfs.root.NotifyEntry(showDirName)
}()

log.Debug("Fecthing movies")
movies, err := pfs.client.GetMovies()
if err != nil {
log.WithField("error", err).Error("Failed to get movies")
dir.rmAllChilds()
dir.rmAllChildren()
return
}

clear(movieInodes)
dir.rmAllChilds()
dir.rmAllChildren()
for _, m := range movies.List() {
imdbID := m.ImdbID
title := movieDirTitle(m)
Expand All @@ -45,8 +50,7 @@ func (pfs *polochonfs) updateMovies() {
continue
}

movieDirNode := newNodeDir(imdbID, title)
movieDirNode.times = m.DateAdded
movieDirNode := newNodeDir(imdbID, title, m.DateAdded)
dir.addChild(movieDirNode)

movieNode := newNode(imdbID, m.Path, url, uint64(m.Size), m.DateAdded)
Expand Down
Loading

0 comments on commit 0b3352e

Please sign in to comment.