From 61dff076d426ada24689356b6f1a08076bb78bcf Mon Sep 17 00:00:00 2001 From: zhengxie Date: Mon, 13 Jul 2015 11:56:09 +0800 Subject: [PATCH] Fix dir/file api path not exists error --- seahub/api2/views.py | 5 ++++- seahub/base/models.py | 5 ++++- seahub/group/views.py | 5 ++++- seahub/utils/repo.py | 3 ++- seahub/views/__init__.py | 4 ++++ seahub/views/file.py | 5 ++++- seahub/views/repo.py | 3 +++ seahub/views/wiki.py | 6 +++++- seahub/wiki/utils.py | 2 ++ 9 files changed, 32 insertions(+), 6 deletions(-) diff --git a/seahub/api2/views.py b/seahub/api2/views.py index ae64fdcc28..6475e66738 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -1852,7 +1852,10 @@ class FileDetailView(APIView): # get real path for sub repo real_path = repo.origin_path + path if repo.origin_path else path dirent = seafile_api.get_dirent_by_path(repo.store_id, real_path) - latest_contributor, last_modified = dirent.modifier, dirent.mtime + if dirent: + latest_contributor, last_modified = dirent.modifier, dirent.mtime + else: + latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 diff --git a/seahub/base/models.py b/seahub/base/models.py index e16347251d..cdc4ada20f 100644 --- a/seahub/base/models.py +++ b/seahub/base/models.py @@ -120,7 +120,10 @@ class UserStarredFilesManager(models.Manager): real_path = sfile.repo.origin_path + sfile.path if sfile.repo.origin_path else sfile.path dirent = seafile_api.get_dirent_by_path(sfile.repo.store_id, real_path) - sfile.last_modified = dirent.mtime + if dirent: + sfile.last_modified = dirent.mtime + else: + sfile.last_modified = 0 except SearpcError as e: logger.error(e) sfile.last_modified = 0 diff --git a/seahub/group/views.py b/seahub/group/views.py index 8073836400..6c710d1308 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -1396,7 +1396,10 @@ def group_wiki(request, group, page_name="home"): path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) - latest_contributor, last_modified = dirent.modifier, dirent.mtime + if dirent: + latest_contributor, last_modified = dirent.modifier, dirent.mtime + else: + latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 diff --git a/seahub/utils/repo.py b/seahub/utils/repo.py index 532bdb85b6..e8e1e28e7d 100644 --- a/seahub/utils/repo.py +++ b/seahub/utils/repo.py @@ -15,7 +15,8 @@ def list_dir_by_path(cmmt, path): if cmmt.root_id == EMPTY_SHA1: return [] else: - return seafile_api.list_dir_by_commit_and_path(cmmt.repo_id, cmmt.id, path) + dirs = seafile_api.list_dir_by_commit_and_path(cmmt.repo_id, cmmt.id, path) + return dirs if dirs else [] def get_sub_repo_abbrev_origin_path(repo_name, origin_path): """Return abbrev path for sub repo based on `repo_name` and `origin_path`. diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index b3e1f8814b..413b758712 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -202,6 +202,8 @@ def get_repo_dirents_with_perm(request, repo, commit, path, offset=-1, limit=-1) else: try: dir_id = seafile_api.get_dir_id_by_path(repo.id, path) + if not dir_id: + return ([], [], False) dirs = seafserv_threaded_rpc.list_dir_with_perm(repo.id, path, dir_id, username, offset, limit) @@ -285,6 +287,8 @@ def get_repo_dirents(request, repo, commit, path, offset=-1, limit=-1): dirs = seafile_api.list_dir_by_commit_and_path(commit.repo_id, commit.id, path, offset, limit) + if not dirs: + return ([], [], False) except SearpcError as e: logger.error(e) return ([], [], False) diff --git a/seahub/views/file.py b/seahub/views/file.py index a83e250745..74107b8390 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -442,7 +442,10 @@ def _file_view(request, repo_id, path): # get real path for sub repo real_path = repo.origin_path + path if repo.origin_path else path dirent = seafile_api.get_dirent_by_path(repo.store_id, real_path) - latest_contributor, last_modified = dirent.modifier, dirent.mtime + if dirent: + latest_contributor, last_modified = dirent.modifier, dirent.mtime + else: + latest_contributor, last_modified = None, 0 except SearpcError as e: logger.error(e) latest_contributor, last_modified = None, 0 diff --git a/seahub/views/repo.py b/seahub/views/repo.py index fc3ab4a1e6..2dd4531c42 100644 --- a/seahub/views/repo.py +++ b/seahub/views/repo.py @@ -374,6 +374,9 @@ def _download_dir_from_share_link(request, fileshare, repo, real_path): dirname = os.path.basename(real_path.rstrip('/')) dir_id = seafile_api.get_dir_id_by_path(repo.id, real_path) + if not dir_id: + return render_error( + request, _(u'Unable to download: folder not found.')) try: total_size = seaserv.seafserv_threaded_rpc.get_dir_size( diff --git a/seahub/views/wiki.py b/seahub/views/wiki.py index 8771905ed0..0ab21cf42f 100644 --- a/seahub/views/wiki.py +++ b/seahub/views/wiki.py @@ -66,8 +66,12 @@ def personal_wiki(request, page_name="home"): path = '/' + dirent.obj_name try: dirent = seafile_api.get_dirent_by_path(repo.id, path) - latest_contributor, last_modified = dirent.modifier, dirent.mtime + if dirent: + latest_contributor, last_modified = dirent.modifier, dirent.mtime + else: + latest_contributor, last_modified = None, 0 except SearpcError as e: + logger.error(e) latest_contributor, last_modified = None, 0 wiki_index_exists = True diff --git a/seahub/wiki/utils.py b/seahub/wiki/utils.py index 456cc5f857..6a4b7a3de3 100644 --- a/seahub/wiki/utils.py +++ b/seahub/wiki/utils.py @@ -98,6 +98,8 @@ def get_wiki_pages(repo): return pages in hashtable {normalized_name: page_name} """ dir_id = seaserv.seafserv_threaded_rpc.get_dir_id_by_path(repo.id, '/') + if not dir_id: + return {} dirs = seafile_api.list_dir_by_dir_id(repo.id, dir_id) pages = {} for e in dirs: