Repository: archlinux/archinstall

Issue:
Error on opening log file
              At commit 5276d95339368210e75791e2b88c1bf5aca4517b, it would seem this commit is broken for me.

On a fresh VM, it complains about having a partition outside of the disk.

```bash
This is an unofficial ISO for development and testing of archinstall. No support will be provided.
This ISO was built from Git SHA 5276d95339368210e75791e2b88c1bf5aca4517b
Type archinstall to launch the installer.
root@archiso ~/archinstall-git # archinstall
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/archinstall/lib/disk/device_handler.py", line 49, in load_devices
    disk = Disk(device)
           ^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/decorators.py", line 42, in new
    ret = fn(*args, **kwds)
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/parted/disk.py", line 52, in __init__
    self.__disk = _ped.Disk(device.getPedDevice())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ped.DiskLabelException: Can't have a partition outside the disk!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/archinstall", line 5, in <module>
    from archinstall import run_as_a_module
  File "/usr/lib/python3.11/site-packages/archinstall/__init__.py", line 8, in <module>
    from .lib import disk
  File "/usr/lib/python3.11/site-packages/archinstall/lib/disk/__init__.py", line 1, in <module>
    from .device_handler import device_handler, disk_layouts
  File "/usr/lib/python3.11/site-packages/archinstall/lib/disk/device_handler.py", line 603, in <module>
    device_handler = DeviceHandler()
                     ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/archinstall/lib/disk/device_handler.py", line 38, in __init__
    self.load_devices()
  File "/usr/lib/python3.11/site-packages/archinstall/lib/disk/device_handler.py", line 54, in load_devices
    debug(f'Unable to get disk from device: {device}')
  File "/usr/lib/python3.11/site-packages/archinstall/lib/output.py", line 259, in debug
    log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
  File "/usr/lib/python3.11/site-packages/archinstall/lib/output.py", line 304, in log
    with open(absolute_logfile, 'a') as fp:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/var/log/archinstall/install.log'
```

_Originally posted by @Reflux0301 in https://github.com/archlinux/archinstall/issues/1828#issuecomment-1555386857_
            


Discussion:

Resolving patch:
diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py
--- a/archinstall/lib/output.py
+++ b/archinstall/lib/output.py
@@ -137,26 +137,28 @@ def log(message: str, level: int = logging.DEBUG) -> None:
 
 def check_log_permissions():
 	filename = storage.get('LOG_FILE', None)
+	log_dir = storage.get('LOG_PATH', Path('./'))
 
 	if not filename:
-		return
+		raise ValueError('No log file name defined')
 
-	log_dir = storage.get('LOG_PATH', Path('./'))
-	absolute_logfile = log_dir / filename
+	log_file = log_dir / filename
 
 	try:
 		log_dir.mkdir(exist_ok=True, parents=True)
-		with absolute_logfile.open('a') as fp:
+		log_file.touch(exist_ok=True)
+
+		with log_file.open('a') as fp:
 			fp.write('')
 	except PermissionError:
 		# Fallback to creating the log file in the current folder
-		fallback_log_file = Path('./').absolute() / filename
-		absolute_logfile = fallback_log_file
-		absolute_logfile.mkdir(exist_ok=True, parents=True)
-		storage['LOG_PATH'] = Path('./').absolute()
+		fallback_dir = Path('./').absolute()
+		fallback_log_file = fallback_dir / filename
 
-		err_string = f"Not enough permission to place log file at {absolute_logfile}, creating it in {fallback_log_file} instead."
-		warn(err_string)
+		fallback_log_file.touch(exist_ok=True)
+
+		storage['LOG_PATH'] = fallback_dir
+		warn(f'Not enough permission to place log file at {log_file}, creating it in {fallback_log_file} instead')
 
 
 def _supports_color() -> bool:
@@ -248,6 +250,7 @@ def info(
 ):
 	log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
 
+
 def debug(
 	*msgs: str,
 	level: int = logging.DEBUG,
@@ -258,6 +261,7 @@ def debug(
 ):
 	log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
 
+
 def error(
 	*msgs: str,
 	level: int = logging.ERROR,
@@ -295,14 +299,10 @@ def log(
 	if _supports_color():
 		text = _stylize_output(text, fg, bg, reset, font)
 
-	# If a logfile is defined in storage,
-	# we use that one to output everything
-	if filename := storage.get('LOG_FILE', None):
-		log_dir = storage.get('LOG_PATH', Path('./'))
-		absolute_logfile = log_dir / filename
+	log_file: Path = storage['LOG_PATH'] / storage['LOG_FILE']
 
-		with open(absolute_logfile, 'a') as fp:
-			fp.write(f"{orig_string}\n")
+	with log_file.open('a') as fp:
+		fp.write(f"{orig_string}\n")
 
 	Journald.log(text, level=level)
 


Test patch: