Exemplo n.º 1
0
def copy_file(fid, did):
    file = file_dal.get_file_by_id(fid)
    dir = file_dal.get_file_by_id(did)
    if file is None and dir is None:
        raise FileManagerException(ErrorCode.ERROR_CODE_FILE_NOT_EXIST)
    _check_file_exist(fid, did)
    parent_dir = dir.fparent + dir.fname if dir.fparent != '-' else '/'
    return file_dal.copy_file(fid, parent_dir)
Exemplo n.º 2
0
def _check_file_exist(fid, did):
    user = request.user or None
    if user is None:
        raise FileManagerException(ErrorCode.ERROR_CODE_REQUIRE_LOGIN)
    file = file_dal.get_file_by_id(fid)
    dir = file_dal.get_file_by_id(did)
    parent_dir = dir.fparent + dir.name if dir.fparent != '-' else '/'
    children = file_dal.get_files_by_dir(parent_dir, user.id)
    for f in children:
        if file.fname == f['file_name']:
            raise FileManagerException(ErrorCode.ERROR_CODE_FILE_EXISTED)
Exemplo n.º 3
0
 def _wrapped(*args, **kwargs):
     fid = get_post_param('fid', 0, int)
     assert fid, 'require param: fid'
     user = request.user
     file = file_dal.get_file_by_id(fid)
     if file.uid != user.id:
         raise FileManagerException(ErrorCode.ERROR_CODE_NO_PERMISSION)
     return func(*args, **kwargs)
Exemplo n.º 4
0
def delete_file(fid):
    file = file_dal.get_file_by_id(fid)
    if file.ftype == 'd':
        file_dal.delete_dir_file(fid)
    else:
        file_dal.delete_regular_file(fid)