Make sure that read-only files can be copied (fix #375)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user