diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-05-16 23:54:52 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-05-16 23:54:52 -0700 |
commit | a6ea5746a7837e555a0a590a232f8ecdaf03fd89 (patch) | |
tree | c97481842a729f6e81c5dfe896844087a266ccfb | |
parent | 360050ed30e257d2e9c3a49f65b5a1c70a6f57cf (diff) | |
download | portage-a6ea5746a7837e555a0a590a232f8ecdaf03fd89.tar.gz portage-a6ea5746a7837e555a0a590a232f8ecdaf03fd89.tar.bz2 portage-a6ea5746a7837e555a0a590a232f8ecdaf03fd89.zip |
--autounmask-write: handle non-existent file
-rw-r--r-- | pym/_emerge/depgraph.py | 22 |
1 files 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) |