Skip to content

Commit

Permalink
[sapphire] Handle long file names
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Sep 29, 2023
1 parent 522a7ac commit db5b39d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions sapphire/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from collections import namedtuple
from enum import Enum, unique
from errno import ENAMETOOLONG
from logging import getLogger
from mimetypes import guess_type
from os.path import splitext
Expand Down Expand Up @@ -143,6 +144,11 @@ def lookup_resource(self, path):
mime=self.lookup_mime(path),
required=required,
)
except OSError as exc:
if exc.errno == ENAMETOOLONG:
# file name is too long to look up so ignore it
return None
raise # pragma: no cover
except ValueError: # pragma: no cover
# this is for compatibility with python versions < 3.8
# is_file() will raise if the path contains characters unsupported
Expand Down
13 changes: 11 additions & 2 deletions sapphire/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,21 @@ def test_job_08(tmp_path):


def test_job_09(tmp_path):
"""test Job.lookup_resource() with file name that is too long"""
(tmp_path / "test.txt").touch()
job = Job(tmp_path)
assert job.status == Served.NONE
assert job.pending == 1
assert job.lookup_resource(f"/{'a' * 8192}.txt") is None


def test_job_10(tmp_path):
"""test Job with missing directory"""
with raises(OSError):
Job(tmp_path / "missing")


def test_job_10(tmp_path):
def test_job_11(tmp_path):
"""test Job.mark_served() and Job.served"""
job = Job(tmp_path)
assert not any(job.served)
Expand All @@ -260,7 +269,7 @@ def test_job_10(tmp_path):
assert "/some/include/path/inc.bin" in job.served


def test_job_11():
def test_job_12():
"""test Job.lookup_mime()"""
assert Job.lookup_mime("unknown") == "application/octet-stream"
# look up from Job.MIME_MAP
Expand Down

0 comments on commit db5b39d

Please sign in to comment.