Correct locking in thread poll watcher
This commit is contained in:
parent
2978e0c968
commit
c31fb24752
|
@ -1,7 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import shutil
|
import shutil
|
||||||
import stat
|
import stat
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from os import stat_result
|
from os import stat_result
|
||||||
|
@ -190,10 +189,10 @@ def watcher_thread_poll(loop):
|
||||||
|
|
||||||
while not quit:
|
while not quit:
|
||||||
rootpath = config.config.path
|
rootpath = config.config.path
|
||||||
old = state.root
|
|
||||||
new = walk()
|
new = walk()
|
||||||
if old != new:
|
|
||||||
with state.lock:
|
with state.lock:
|
||||||
|
old = state.root
|
||||||
|
if old != new:
|
||||||
state.root = new
|
state.root = new
|
||||||
broadcast(format_update(old, new), loop)
|
broadcast(format_update(old, new), loop)
|
||||||
|
|
||||||
|
@ -333,8 +332,9 @@ async def abroadcast(msg):
|
||||||
|
|
||||||
async def start(app, loop):
|
async def start(app, loop):
|
||||||
config.load_config()
|
config.load_config()
|
||||||
|
use_inotify = False # sys.platform == "linux"
|
||||||
app.ctx.watcher = threading.Thread(
|
app.ctx.watcher = threading.Thread(
|
||||||
target=watcher_thread if sys.platform == "linux" else watcher_thread_poll,
|
target=watcher_thread if use_inotify else watcher_thread_poll,
|
||||||
args=[loop],
|
args=[loop],
|
||||||
)
|
)
|
||||||
app.ctx.watcher.start()
|
app.ctx.watcher.start()
|
||||||
|
|
|
@ -135,7 +135,7 @@ function handleUpdateMessage(updateData: { update: UpdateEntry[] }) {
|
||||||
else console.log("Unknown update action", action, arg)
|
else console.log("Unknown update action", action, arg)
|
||||||
}
|
}
|
||||||
if (oidx != tree.length)
|
if (oidx != tree.length)
|
||||||
throw Error(`Tree update out of sync, number of entries mismatch: got ${oidx}, expected ${tree.length}`)
|
throw Error(`Tree update out of sync, number of entries mismatch: got ${oidx}, expected ${tree.length}, new tree ${newtree.length}`)
|
||||||
store.updateRoot(newtree)
|
store.updateRoot(newtree)
|
||||||
tree = newtree
|
tree = newtree
|
||||||
saveSession()
|
saveSession()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { defineStore } from 'pinia'
|
||||||
import { collator } from '@/utils'
|
import { collator } from '@/utils'
|
||||||
import { logoutUser } from '@/repositories/User'
|
import { logoutUser } from '@/repositories/User'
|
||||||
import { watchConnect } from '@/repositories/WS'
|
import { watchConnect } from '@/repositories/WS'
|
||||||
import { format } from 'path'
|
|
||||||
|
|
||||||
type FileData = { id: string; mtime: number; size: number; dir: DirectoryData }
|
type FileData = { id: string; mtime: number; size: number; dir: DirectoryData }
|
||||||
type DirectoryData = {
|
type DirectoryData = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user