BigFile lock seek and read until previous request finished, fix seek relative to bigfile end
This commit is contained in:
parent
f5ab2f63c0
commit
879eb6295d
2 changed files with 42 additions and 35 deletions
|
@ -3,10 +3,11 @@ import os
|
|||
import subprocess
|
||||
import shutil
|
||||
import collections
|
||||
import gevent
|
||||
import math
|
||||
|
||||
import msgpack
|
||||
import gevent
|
||||
import gevent.lock
|
||||
|
||||
from Plugin import PluginManager
|
||||
from Debug import Debug
|
||||
|
@ -475,8 +476,10 @@ class BigFile(object):
|
|||
|
||||
self.piecefield = self.site.storage.piecefields[self.sha512]
|
||||
self.f = open(file_path, "rb+")
|
||||
self.read_lock = gevent.lock.Semaphore()
|
||||
|
||||
def read(self, buff=64 * 1024):
|
||||
with self.read_lock:
|
||||
pos = self.f.tell()
|
||||
read_until = min(self.size, pos + buff)
|
||||
requests = []
|
||||
|
@ -519,8 +522,12 @@ class BigFile(object):
|
|||
|
||||
return self.f.read(buff)
|
||||
|
||||
def seek(self, pos):
|
||||
return self.f.seek(pos)
|
||||
def seek(self, pos, whence=0):
|
||||
with self.read_lock:
|
||||
if whence == 2: # Relative from file end
|
||||
pos = self.size + pos # Use the real size instead of size on the disk
|
||||
whence = 0
|
||||
return self.f.seek(pos, whence)
|
||||
|
||||
def tell(self):
|
||||
self.f.tell()
|
||||
|
|
|
@ -10,7 +10,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.6.3"
|
||||
self.rev = 3546
|
||||
self.rev = 3549
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.pending_changes = {}
|
||||
|
|
Loading…
Reference in a new issue