bugfix
This commit is contained in:
parent
f596df7696
commit
5d06576763
@ -105,11 +105,22 @@ class FileStorage:
|
||||
name))
|
||||
return path
|
||||
|
||||
def remove(self, path):
|
||||
try:
|
||||
if path[0] == '/':
|
||||
path = path[1:]
|
||||
p = os.path.join(self.root, path)
|
||||
os.remove(p)
|
||||
except Exception as e:
|
||||
exception(f'{path=}, {p=} remove error')
|
||||
|
||||
async def save(self,name,read_data, userid=None):
|
||||
p = self._name2path(name, userid=userid)
|
||||
fpath = p[len(self.root):]
|
||||
info(f'{p=}, {fpath=},{self.root} ')
|
||||
_mkdir(os.path.dirname(p))
|
||||
if isinstance(read_data, str) or isinstance(read_data, bytes):
|
||||
b = read_data
|
||||
if isinstance(read_data, str):
|
||||
b = read_data.encode('utf-8')
|
||||
async with aiofiles.open(p, 'wb') as f:
|
||||
@ -117,6 +128,7 @@ class FileStorage:
|
||||
await f.flush()
|
||||
self.tfr.newtmpfile(fpath)
|
||||
return fpath
|
||||
|
||||
async with aiofiles.open(p,'wb') as f:
|
||||
siz = 0
|
||||
while 1:
|
||||
|
@ -34,7 +34,7 @@ from .xlsxData import XLSXData
|
||||
from .uriop import URIOp
|
||||
from .error import Success, Error, NeedLogin, NoPermission
|
||||
from .filetest import current_fileno
|
||||
|
||||
from .filestorage import FileStorage
|
||||
from .serverenv import ServerEnv
|
||||
|
||||
def data2xlsx(rows,headers=None):
|
||||
@ -57,6 +57,11 @@ def data2xlsx(rows,headers=None):
|
||||
wb.close()
|
||||
return name
|
||||
|
||||
async def save_file(str_or_bytes, filename):
|
||||
fs = FileStorage()
|
||||
r = await fs.save(filename, str_or_bytes)
|
||||
return r
|
||||
|
||||
class FileOutZone(Exception):
|
||||
def __init__(self,fp,*args,**kwargs):
|
||||
super(FileOutZone,self).__init__(*args,**kwargs)
|
||||
@ -193,6 +198,7 @@ def initEnv():
|
||||
g.DictObject = DictObject
|
||||
g.async_sleep = asyncio.sleep
|
||||
g.quotedstr = quotedstr
|
||||
g.save_file = save_file
|
||||
|
||||
def set_builtins():
|
||||
all_builtins = [ i for i in dir(builtins) if not i.startswith('_')]
|
||||
|
Loading…
Reference in New Issue
Block a user