def __init__(self, name, path): self.name = name self.path = path if path: self.size = format_filesize(get_filesize(path)) else: self.size = 0
def getTotalSize(conn): files = conn.runQuery("select filename from nodefile") size = 0 rootpath = config.get("paths.datadir") for file in files: size += get_filesize(os.path.join(rootpath, file[0])) return size
def update_sha512(self): """Overwrite the stored checksum value with the current checksum of the file on disk. Use with caution, should not be necessary under usual circumstances!""" if not self.exists: return None logg.info('Updating sha512 for file ID: %s.' % self.id) self.sha512 = self.calculate_sha512() self.sha512_ok = True self.sha512_created_at = self.sha512_checked_at = datetime.utcnow() self._size = get_filesize(self.path) return self.sha512
def getSize(self): for f in filehandlers: if hasattr(f, "getSize"): try: size = f.getSize(self) if size: return size else: return 0 except: logException("file handler getSize() failed") return -1 return get_filesize(self.retrieveFile())
def send_attfile(req): """send single attachment file to user""" parts = req.path[9:].split('/') if len(parts) < 2: return 400 nid = userinput.string_to_int(parts[0]) if nid is None: return 400 version_id = version_id_from_req(req) node = get_node_or_version(nid, version_id, Data) # XXX: why do we want to send attachments from containers? if (node is None or isinstance(node, Container) and not node.has_read_access() or isinstance(node, Content) and not node.has_data_access()): return 404 paths = ["/".join(parts[1:]), "/".join(parts[1:-1])] fileobjs = [fo for fo in node.files if fo.path in paths] if not fileobjs: return 404 fileobj = fileobjs[0] if fileobj.mimetype == u'inode/directory': # files in attachment directory cannot be found in node.files # so send file directly as it was made in mysql filename = clean_path("/".join(parts[1:])) path = os.path.join(config.get("paths.datadir"), filename) mime, type = getMimeType(filename) if (get_filesize(filename) > 16 * 1048576): req.reply_headers[ "Content-Disposition"] = 'attachment; filename="{}"'.format( filename) return req.sendFile(path, mime) if (fileobj.size > 16 * 1048576): req.reply_headers[ "Content-Disposition"] = u'attachment; filename="{}"'.format( fileobj.base_name).encode('utf8') return req.sendFile(fileobj.abspath, fileobj.mimetype)
def send_attfile(req): """send single attachment file to user""" parts = req.path[9:].split('/') if len(parts) < 2: return 400 nid = userinput.string_to_int(parts[0]) if nid is None: return 400 version_id = version_id_from_req(req) node = get_node_or_version(nid, version_id, Data) # XXX: why do we want to send attachments from containers? if (node is None or isinstance(node, Container) and not node.has_read_access() or isinstance(node, Content) and not node.has_data_access()): return 404 paths = ["/".join(parts[1:]), "/".join(parts[1:-1])] fileobjs = [fo for fo in node.files if fo.path in paths] if not fileobjs: return 404 fileobj = fileobjs[0] if fileobj.mimetype == u'inode/directory': # files in attachment directory cannot be found in node.files # so send file directly as it was made in mysql filename = clean_path("/".join(parts[1:])) path = os.path.join(config.get("paths.datadir"), filename) mime, type = getMimeType(filename) if (get_filesize(filename) > 16 * 1048576): req.reply_headers["Content-Disposition"] = 'attachment; filename="{}"'.format(filename) return req.sendFile(path, mime) if (fileobj.size > 16 * 1048576): req.reply_headers["Content-Disposition"] = u'attachment; filename="{}"'.format(fileobj.base_name).encode('utf8') return req.sendFile(fileobj.abspath, fileobj.mimetype)
def send_attfile(req): access = AccessData(req) f = req.path[9:].split('/') try: node = getNode(f[0]) except tree.NoSuchNodeError: return 404 if not access.hasAccess(node, "data") and node.type != "directory": return 403 if len([file for file in node.getFiles() if file._path in ["/".join(f[1:]), "/".join(f[1:-1])]]) == 0: # check filepath return 403 filename = clean_path("/".join(f[1:])) path = join_paths(config.get("paths.datadir"), filename) mime, type = getMimeType(filename) if(get_filesize(filename) > 16 * 1048576): req.reply_headers["Content-Disposition"] = 'attachment; filename="{}"'.format(filename) return req.sendFile(path, mime)
def send_attfile(req): access = AccessData(req) f = req.path[9:].split('/') try: node = getNode(f[0]) except tree.NoSuchNodeError: return 404 if not access.hasAccess(node, "data") and node.type != "directory": return 403 if len([ file for file in node.getFiles() if file._path in ["/".join(f[1:]), "/".join(f[1:-1])] ]) == 0: # check filepath return 403 filename = clean_path("/".join(f[1:])) path = join_paths(config.get("paths.datadir"), filename) mime, type = getMimeType(filename) if (get_filesize(filename) > 16 * 1048576): req.reply_headers[ "Content-Disposition"] = 'attachment; filename="{}"'.format( filename) return req.sendFile(path, mime)
def build_filelist(node): "build file list for generation of xmetadissplus xml" if not (isinstance(node, Content) and node.has_data_access()): return [] files_written = 0 result_list = [] # limit transfer.zip to one node for n in [node]: if n.isActiveVersion(): for fn in n.files: if fn.filetype in ['document', 'zip', 'attachment', 'other']: fullpath = fn.abspath if os.path.isfile(fullpath) and os.path.exists(fullpath): dirname, filename = os.path.split(fullpath) result_list.append([filename, fn.getSize()]) files_written += 1 if os.path.isdir(fullpath): for f in get_all_file_paths(fullpath): dirname, filename = os.path.split(f) result_list.append([filename, get_filesize(f)]) files_written += 1 return result_list
def size(self): """Return size of file in bytes""" if self._size is None: self._size = get_filesize(self.path) return self._size