mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Fix copy_file_if_changed src permissions copied too (#3161)
This commit is contained in:
parent
ab47e201c7
commit
253161d3d0
1 changed files with 14 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
import codecs
|
||||
from contextlib import suppress
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
@ -233,8 +234,20 @@ def copy_file_if_changed(src: os.PathLike, dst: os.PathLike) -> None:
|
|||
return
|
||||
mkdir_p(os.path.dirname(dst))
|
||||
try:
|
||||
shutil.copy(src, dst)
|
||||
shutil.copyfile(src, dst)
|
||||
except OSError as err:
|
||||
if isinstance(err, PermissionError):
|
||||
# Older esphome versions copied over the src file permissions too.
|
||||
# So when the dst file had 444 permissions, the dst file would have those
|
||||
# too and subsequent writes would fail
|
||||
|
||||
# -> delete file (it would be overwritten anyway), and try again
|
||||
# if that fails, use normal error handler
|
||||
with suppress(OSError):
|
||||
os.unlink(dst)
|
||||
shutil.copyfile(src, dst)
|
||||
return
|
||||
|
||||
from esphome.core import EsphomeError
|
||||
|
||||
raise EsphomeError(f"Error copying file {src} to {dst}: {err}") from err
|
||||
|
|
Loading…
Reference in a new issue