def list_path(path='.'): """Return a list of files in a path if permitted """ try: real_path = protect_path(path) except IOError: abort(403, PATH_ERROR) if request.GET.get('format', 'raw').strip() == 'zip': print('got zip') archive = archive_path(real_path) return list_dir(archive) return list_dir(real_path)
def test_list_dir_folder(aaa): """Get a list of files in a specific folder""" prep_folder() aaa.user_is_anonymous = True ls = t.list_dir("/tmp/test") del_folder() assert {"name", "size", "mtime"} == set(ls["dirs"][0].keys()) assert {"name", "size", "mtime"} == set(ls["files"][0].keys())
def list_shared(user, uid, path='.'): """If the path is a file: return it's content if the path is a folder: return a list of files in the folder if parameter 'format' is specified return the path in the specified format (zip only for now) """ real_shared_path = get_path_from_uid(user, uid) # print(real_shared_path) permitted = join_path(root_dir, real_shared_path) try: real_path = get_real_path(permitted, path) except IOError: abort(403, PATH_ERROR) # print("getting {}".format(real_path)) print(request.GET.keys()) if request.GET.get('format', 'raw').strip() == 'zip': print('got zip') archive = archive_path(real_path) return list_dir(archive) return list_dir(real_path)
def test_list_dir_file(static_file): """Listing a 'file' gives us it's content or path when not in debug""" prep_folder() t.list_dir("/tmp/test/file") del_folder() assert static_file.called