Skip to content
Permalink
Browse files

Make sure that read-only files can be copied (fix #375)

  • Loading branch information
saimn committed Oct 4, 2019
1 parent 745761f commit 45de6e7b6de7993ab5af6d09d77a663151c056a7
Showing with 17 additions and 1 deletion.
  1. +7 −1 sigal/utils.py
  2. +10 −0 tests/test_utils.py
@@ -50,7 +50,13 @@ def copy(src, dst, symlink=False, rellink=False):
if rellink: # relative symlink from dst
func(os.path.relpath(src, os.path.dirname(dst)), dst)
else:
func(src, dst)
try:
func(src, dst)
except PermissionError:
# this can happen if the file is not writable, so we try to remove
# it first
os.remove(dst)
func(src, dst)


def check_or_create_dir(path):
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from sigal import utils

CURRENT_DIR = os.path.dirname(__file__)
@@ -33,6 +34,15 @@ def test_copy(tmpdir):
assert os.path.join(os.path.dirname(CURRENT_DIR)), os.readlink(dst) == src
# get absolute path of the current dir plus the relative dir

src = str(tmpdir.join('foo.txt'))
dst = str(tmpdir.join('bar.txt'))
p = Path(src)
p.touch()
p.chmod(0o444)
utils.copy(src, dst)
utils.copy(src, dst)


def test_check_or_create_dir(tmpdir):
path = str(tmpdir.join('new_directory'))
utils.check_or_create_dir(path)

0 comments on commit 45de6e7

Please sign in to comment.
You can’t perform that action at this time.