Skip to content

Commit 2660b75

Browse files
gregdelPouuleT
authored andcommitted
Notify the kernel of node updates
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
1 parent a790436 commit 2660b75

File tree

5 files changed

+84
-118
lines changed

5 files changed

+84
-118
lines changed

cmd/polochonfs/fs.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
logger "log"
77
"os"
88
"os/signal"
9+
"sync"
910
"syscall"
1011
"time"
1112

@@ -24,6 +25,7 @@ var (
2425
type polochonfs struct {
2526
fuseDebug bool
2627
ctx context.Context
28+
wg sync.WaitGroup
2729

2830
root *node
2931

@@ -47,10 +49,12 @@ func (pfs *polochonfs) init() error {
4749
{value: polochonToken, errMsg: "missing token"},
4850
} {
4951
if field.value == "" {
50-
return fmt.Errorf(field.errMsg)
52+
return fmt.Errorf("%s", field.errMsg)
5153
}
5254
}
5355

56+
pfs.wg = sync.WaitGroup{}
57+
5458
var err error
5559
pfs.client, err = papi.New(polochonURL)
5660
if err != nil {
@@ -62,19 +66,27 @@ func (pfs *polochonfs) init() error {
6266
return nil
6367
}
6468

69+
func (pfs *polochonfs) wait() {
70+
pfs.wg.Wait()
71+
}
72+
6573
func (pfs *polochonfs) buildFS(_ context.Context) {
66-
log.Debug("Adding persistent nodes")
67-
pfs.root.addChild(newPersistentNodeDir(movieDirName))
68-
pfs.root.addChild(newPersistentNodeDir(showDirName))
74+
pfs.root.addChild(newNodeDir(movieDirName, movieDirName, pfs.root.times))
75+
pfs.root.addChild(newNodeDir(showDirName, showDirName, pfs.root.times))
6976

70-
pfs.updateMovies()
71-
pfs.updateShows()
77+
go pfs.handleUpdates()
7278
}
7379

7480
func (pfs *polochonfs) handleUpdates() {
81+
pfs.wg.Add(1)
82+
defer pfs.wg.Done()
83+
7584
sigs := make(chan os.Signal, 1)
7685
signal.Notify(sigs, syscall.SIGUSR1, syscall.SIGUSR2)
7786

87+
pfs.updateMovies()
88+
pfs.updateShows()
89+
7890
ticker := time.NewTicker(libraryRefresh)
7991
defer ticker.Stop()
8092

@@ -84,9 +96,11 @@ func (pfs *polochonfs) handleUpdates() {
8496
switch s {
8597
case syscall.SIGUSR1:
8698
log.Info("Updating movies from signal")
99+
ticker.Reset(libraryRefresh)
87100
pfs.updateMovies()
88101
case syscall.SIGUSR2:
89102
log.Info("Updating shows from signal")
103+
ticker.Reset(libraryRefresh)
90104
pfs.updateShows()
91105
}
92106
case <-ticker.C:

cmd/polochonfs/main.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os/signal"
88
"os/user"
99
"strconv"
10-
"sync"
1110
"syscall"
1211
"time"
1312

@@ -114,20 +113,14 @@ func run() error {
114113
return err
115114
}
116115

117-
wg := sync.WaitGroup{}
118-
go func() {
119-
wg.Add(1)
120-
defer wg.Done()
121-
pfs.handleUpdates()
122-
}()
123-
124116
log.Info("FUSE daemon started")
125117
sigs := make(chan os.Signal, 1)
126118
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
127119
<-sigs
128120
cancel()
129121

130-
wg.Wait()
122+
pfs.wait()
123+
131124
pfs.unmount(server)
132125
return nil
133126
}

cmd/polochonfs/movies.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ func movieDirTitle(m *papi.Movie) string {
2323
func (pfs *polochonfs) updateMovies() {
2424
dir := pfs.root.getChild(movieDirName)
2525

26+
defer func() {
27+
pfs.root.addChild(dir)
28+
_ = pfs.root.NotifyEntry(showDirName)
29+
}()
30+
2631
log.Debug("Fecthing movies")
2732
movies, err := pfs.client.GetMovies()
2833
if err != nil {
2934
log.WithField("error", err).Error("Failed to get movies")
30-
dir.rmAllChilds()
35+
dir.rmAllChildren()
3136
return
3237
}
3338

3439
clear(movieInodes)
35-
dir.rmAllChilds()
40+
dir.rmAllChildren()
3641
for _, m := range movies.List() {
3742
imdbID := m.ImdbID
3843
title := movieDirTitle(m)
@@ -45,8 +50,7 @@ func (pfs *polochonfs) updateMovies() {
4550
continue
4651
}
4752

48-
movieDirNode := newNodeDir(imdbID, title)
49-
movieDirNode.times = m.DateAdded
53+
movieDirNode := newNodeDir(imdbID, title, m.DateAdded)
5054
dir.addChild(movieDirNode)
5155

5256
movieNode := newNode(imdbID, m.Path, url, uint64(m.Size), m.DateAdded)

0 commit comments

Comments
 (0)