Skip to content

Commit

Permalink
[makeotf] Delete zero-size font on failure
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
miguelsousa committed Feb 9, 2019
1 parent cd56b34 commit a86aeff
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/afdko/makeotf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""

__version__ = """\
makeotf.py v2.7.0 Feb 8 2019
makeotf.py v2.7.1 Feb 9 2019
"""

__methods__ = """
Expand Down Expand Up @@ -2570,6 +2570,11 @@ def runMakeOTF(makeOTFParams):
if not os.path.exists(tempOutPath) or (os.path.getsize(tempOutPath) < 500):
print("makeotf [Error] Failed to build output font file '%s'." %
tempOutPath)
if os.path.exists(tempOutPath):
try:
os.remove(tempOutPath)
except OSError:
pass
raise MakeOTFRunError

if makeOTFParams.srcIsTTF:
Expand All @@ -2578,6 +2583,11 @@ def runMakeOTF(makeOTFParams):
if not os.path.exists(outputPath) or (os.path.getsize(outputPath) < 500):
print("makeotf [Error] Failed to build output font file '%s'." %
outputPath)
if os.path.exists(outputPath):
try:
os.remove(outputPath)
except OSError:
pass
raise MakeOTFRunError

# The following check is here because of the internal Adobe
Expand Down
4 changes: 4 additions & 0 deletions tests/makeotf_data/input/bug736/feat.fea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

table head {
FontRevisio 1.011;
} head;
65 changes: 65 additions & 0 deletions tests/makeotf_data/input/bug736/font.pfa

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/makeotf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,16 @@ def test_unhandled_ufo_glif_token_bug705():
with open(stderr_path, 'rb') as f:
output = f.read()
assert b"unhandled token: <foo" in output


def test_delete_zero_kb_font_on_fail_bug736():
input_filename = 'bug736/font.pfa'
feat_filename = 'bug736/feat.fea'
out_filename = 'bug736/SourceSans-Test.otf'

with pytest.raises(subprocess.CalledProcessError) as err:
runner(CMD + ['-o',
'f', '_{}'.format(get_input_path(input_filename)),
'ff', '_{}'.format(get_input_path(feat_filename))])
assert err.value.returncode == 1
assert os.path.exists(get_input_path(out_filename)) is False

0 comments on commit a86aeff

Please sign in to comment.