1
0
mirror of synced 2024-11-24 18:24:23 +01:00

Copy file permissions

Mat2 (the cli) will now copy the input file permissions
to the output file.
This commit is contained in:
jvoisin 2019-10-13 11:54:47 +02:00
parent 5f0b3beb46
commit 4034cf9a1a
2 changed files with 30 additions and 0 deletions

2
mat2
View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
import shutil
from typing import Tuple, List, Union, Set
import sys
import mimetypes
@ -136,6 +137,7 @@ def clean_meta(filename: str, is_lightweight: bool, inplace: bool, sandbox: bool
try:
logging.debug('Cleaning %s…', filename)
ret = p.remove_all()
shutil.copymode(filename, p.output_filename)
if inplace is True:
os.rename(p.output_filename, filename)
return ret

View File

@ -1,6 +1,7 @@
import random
import os
import shutil
import stat
import subprocess
import unittest
import glob
@ -132,6 +133,33 @@ class TestCleanMeta(unittest.TestCase):
self.assertNotIn(b'Comment: Created with GIMP', stdout)
os.remove('./tests/data/clean.jpg')
os.remove('./tests/data/clean.cleaned.jpg')
class TestCopyPermissions(unittest.TestCase):
def test_jpg_777(self):
shutil.copy('./tests/data/dirty.jpg', './tests/data/clean.jpg')
os.chmod('./tests/data/clean.jpg', 0o777)
proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.jpg'],
stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
self.assertIn(b'Comment: Created with GIMP', stdout)
proc = subprocess.Popen(mat2_binary + ['./tests/data/clean.jpg'],
stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/clean.cleaned.jpg'],
stdout=subprocess.PIPE)
stdout, _ = proc.communicate()
self.assertNotIn(b'Comment: Created with GIMP', stdout)
permissions = os.stat('./tests/data/clean.cleaned.jpg')[stat.ST_MODE]
self.assertEqual(permissions, 0o100777)
os.remove('./tests/data/clean.jpg')
os.remove('./tests/data/clean.cleaned.jpg')
class TestIsSupported(unittest.TestCase):