Skip to content
Snippets Groups Projects
Commit 356dfa27 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

cvsclient: Handle error in fetch_rlog when path does not exist

When attempting to fetch the rlog for a path that does not exist in
the repository, the CVS server will respond with the following lines:

E cvs rlog: could not read RCS file for <path>
ok

That error case was not handled in fetch_rlog so ensure it returns None
when encountering it.

The issue was spotted when the loader attempts to fetch more rlog data from
Attic directories. The paths of these Attic directories are computed from
those of the files in the repositories but it exist cases where those
directories do not exist.
parent 83fae9c7
No related branches found
No related tags found
No related merge requests found
......@@ -339,9 +339,12 @@ class CVSClient:
if response is None:
raise CVSProtocolError("No response from CVS server")
if response[0:2] == b"E ":
if len(path) > 0 and response[-11:] == b" - ignored\n":
if len(path) > 0 and (
response.endswith(b" - ignored\n")
or b"could not read RCS file" in response
):
response = self.conn_read_line()
if response != b"error \n":
if response not in (b"error \n", b"ok\n"):
raise CVSProtocolError(
"Invalid response from CVS server: %s" % response
)
......
# Copyright (C) 2022 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
from urllib.parse import urlparse
from swh.loader.cvs.cvsclient import CVSClient
def test_cvs_client_rlog_could_not_read_rcs_file(mocker):
url = "ssh://anoncvs@anoncvs.example.org/cvsroot/src"
file = "src/README.txt"
mocker.patch("swh.loader.cvs.cvsclient.socket")
conn_read_line = mocker.patch.object(CVSClient, "conn_read_line")
conn_read_line.side_effect = [
# server response lines when client is initialized
b"Valid-requests ",
b"ok\n",
# server response lines when attempting to fetch rlog of a file
# but RCS file is missing
f"E cvs rlog: could not read RCS file for {file}\n".encode(),
b"ok\n",
]
client = CVSClient(urlparse(url))
assert client.fetch_rlog(file.encode()) is None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment