1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 15:39:43 +00:00

Follow symlinks when resolving a templated file

This commit is contained in:
Joey Territo
2023-07-22 15:17:14 -05:00
committed by deadc0de
parent a2de4cfb0c
commit 9954a21e3f

View File

@@ -179,8 +179,7 @@ class Templategen:
"""add a comment usually in the header of a dotfile"""
return f'{prepend}{utils.header()}'
def _handle_file(self, src):
"""generate the file content from template"""
def _get_filetype(self, src):
try:
# pylint: disable=C0415
import magic
@@ -188,10 +187,22 @@ class Templategen:
self.log.dbg('using \"magic\" for filetype identification')
except ImportError:
# fallback
_, filetype = utils.run(['file', '-b', '--mime-type', src],
_, filetype = utils.run(['file', '-L', '-b', '--mime-type', src],
debug=self.debug)
self.log.dbg('using \"file\" for filetype identification')
filetype = filetype.strip()
if filetype == 'inode/symlink':
dst = os.readlink(src)
if dst[0] != '/':
# Canonicalize relative path
dst = os.path.join(os.path.dirname(src), dst)
return self._get_filetype(dst)
else:
return filetype
def _handle_file(self, src):
"""generate the file content from template"""
filetype = self._get_filetype(src)
istext = self._is_text(filetype)
self.log.dbg(f'filetype \"{src}\": {filetype}')
self.log.dbg(f'is text \"{src}\": {istext}')