nixpkgs/pkgs/tools/misc/esphome/fix-src-permissions.patch
Martin Weinelt 06d92ba195
esphome: fix permissions on src file before modifying them
We store esphome in the nix store, which results in its file permissions
being 0444. Esphome, when compiling a firmware image, will copy these
files from the nix store to a working directory. When updating between
versions it will notice these files changed and try to copy the new
version over, which would break, because the user had no write
permissions on the files.

❯ esphome compile 01e4ac.yml
INFO Reading configuration 01e4ac.yml...
INFO Detected timezone 'CET' with UTC offset 1 and daylight saving time from 27 March 02:00:00 to 30 October 03:00:00
INFO Generating C++ source...
ERROR Error copying file /nix/store/lmzrgl1arqfd98jcss4rsmmy6dbffddn-esphome-1.19.2/lib/python3.8/site-packages/esphome/components/api/api_connection.cpp to 01e4ac/src/esphome/components/api/api_connection.cpp: [Errno 13] Permission denied: '01e4ac/src/esphome/components/api/api_connection.cpp'

To fix this we modify chmod to 0644 just before esphome tries a copy
operation, which will fix permissions on existing working directories
just in time.
2021-06-23 05:07:11 +02:00

47 lines
1.9 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From f72c5035944065941daaa236b60664657c777726 Mon Sep 17 00:00:00 2001
From: Martin Weinelt <hexa@darmstadt.ccc.de>
Date: Wed, 23 Jun 2021 04:50:35 +0200
Subject: [PATCH] Set u+w for copied src files before trying to overwrite them
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We store esphome in the nix store, which results in its file permissions
being 0444. Esphome, when compiling a firmware image, will copy these
files from the nix store to a working directory. When updating between
versions it will notice these files changed and try to copy the new
version over, which would break, because the user had no write
permissions on the files.
esphome compile 01e4ac.yml
INFO Reading configuration 01e4ac.yml...
INFO Detected timezone 'CET' with UTC offset 1 and daylight saving time from 27 March 02:00:00 to 30 October 03:00:00
INFO Generating C++ source...
ERROR Error copying file /nix/store/lmzrgl1arqfd98jcss4rsmmy6dbffddn-esphome-1.19.2/lib/python3.8/site-packages/esphome/components/api/api_connection.cpp to 01e4ac/src/esphome/components/api/api_connection.cpp: [Errno 13] Permission denied: '01e4ac/src/esphome/components/api/api_connection.cpp'
To fix this we modify chmod to 0644 just before esphome tries a copy
operation, which will fix permissions on existing working directories
just in time.
---
esphome/helpers.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/esphome/helpers.py b/esphome/helpers.py
index ad7b8272..c456f4ff 100644
--- a/esphome/helpers.py
+++ b/esphome/helpers.py
@@ -228,6 +228,10 @@ def copy_file_if_changed(src: os.PathLike, dst: os.PathLike) -> None:
if file_compare(src, dst):
return
mkdir_p(os.path.dirname(dst))
+ try:
+ os.chmod(dst, 0o644)
+ except OSError:
+ pass
try:
shutil.copy(src, dst)
except OSError as err:
--
2.31.1