forked from archive/andrewferrier_email2pdf
Handle moving tempfile between mountpoints.
This commit is contained in:
parent
dca9824b35
commit
e658f6dc8b
3 changed files with 20 additions and 3 deletions
2
debian/DEBIAN/control
vendored
2
debian/DEBIAN/control
vendored
|
@ -1,5 +1,5 @@
|
|||
Package: email2pdf
|
||||
Version: 0.3
|
||||
Version: 0.3.1
|
||||
Section: base
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
|
|
|
@ -16,6 +16,7 @@ import magic
|
|||
import os
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
@ -218,8 +219,7 @@ def add_update_pdf_metadata(filename, updateDictionary):
|
|||
with open(temp_file_name, 'wb') as file_out:
|
||||
pdf_output.write(file_out)
|
||||
|
||||
os.unlink(filename)
|
||||
os.rename(temp_file_name, filename)
|
||||
shutil.move(temp_file_name, filename)
|
||||
|
||||
|
||||
def extract_part_filename(part):
|
||||
|
|
|
@ -132,6 +132,11 @@ class BaseTestClasses:
|
|||
else:
|
||||
return None
|
||||
|
||||
def find_mount_point(self, path):
|
||||
while not os.path.ismount(path):
|
||||
path=os.path.dirname(path)
|
||||
return path
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.workingDir)
|
||||
|
||||
|
@ -176,6 +181,18 @@ class TestBasic(BaseTestClasses.Email2PDFTestCase):
|
|||
self.assertEqual("Subject of the email", self.getMetadataField(path, "Title"))
|
||||
self.assertEqual("email2pdf", self.getMetadataField(path, "Producer"))
|
||||
|
||||
def test_plaincontent_metadata_differentmount(self):
|
||||
self.addHeaders("from@example.org")
|
||||
self.setPlainContent("Hello!")
|
||||
mountPoint2 = tempfile.mkdtemp(dir='/var/tmp')
|
||||
if(self.find_mount_point(mountPoint2) != self.find_mount_point(tempfile.tempdir)):
|
||||
path = os.path.join(mountPoint2, "plaincontent_metadata_differentmount.pdf")
|
||||
self.assertEqual(0, self.invokeEmail2PDF(outputFile=path))
|
||||
self.assertTrue(os.path.exists(path))
|
||||
self.assertEqual("from@example.org", self.getMetadataField(path, "Author"))
|
||||
else:
|
||||
self.skipTest(mountPoint2 + " and " + tempfile.tempdir + " are on the same mountpoint, test not relevant.")
|
||||
|
||||
def test_noheaders_metadata(self):
|
||||
self.setPlainContent("Hello!")
|
||||
path = os.path.join(examineDir, "plaincontent_noheaders_metadata.pdf")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue