From a6ea5746a7837e555a0a590a232f8ecdaf03fd89 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 16 May 2011 23:54:52 -0700 Subject: [PATCH] --autounmask-write: handle non-existent file --- pym/_emerge/depgraph.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 3daaf441c..9f3c1ac71 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -5,6 +5,7 @@ from __future__ import print_function import codecs import difflib +import errno import gc import logging import re @@ -5672,6 +5673,18 @@ class depgraph(object): no suitable file exists. """ file_path = os.path.join(abs_user_config, file_name) + + try: + os.lstat(file_path) + except OSError as e: + if e.errno == errno.ENOENT: + # The file doesn't exist, so we'll + # simply create it. + return file_path + + # Disk or file system trouble? + return None + last_file_path = None stack = [file_path] while stack: @@ -5759,6 +5772,7 @@ class depgraph(object): shlex_split(settings.get("CONFIG_PROTECT_MASK", ""))) def write_changes(root, changes, file_to_write_to): + file_contents = None try: file_contents = codecs.open( _unicode_encode(file_to_write_to, @@ -5766,8 +5780,12 @@ class depgraph(object): mode='r', encoding=_encodings['content'], errors='replace').readlines() except IOError as e: - problems.append("!!! Failed to read '%s': %s\n" % (file_to_write_to, e)) - else: + if e.errno == errno.ENOENT: + file_contents = [] + else: + problems.append("!!! Failed to read '%s': %s\n" % \ + (file_to_write_to, e)) + if file_contents is not None: file_contents.extend(changes) if protect_obj[root].isprotected(file_to_write_to): file_to_write_to = new_protect_filename(file_to_write_to) -- 2.26.2