Skip to content
Snippets Groups Projects
Commit 4034cf9a authored by Julien (jvoisin) Voisin's avatar Julien (jvoisin) Voisin
Browse files

Copy file permissions

Mat2 (the cli) will now copy the input file permissions
to the output file.
parent 5f0b3beb
No related branches found
No related tags found
1 merge request!65Copy file permissions
Pipeline #28298 passed
#!/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
......
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):
......
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