Commit 7a3fc243 authored by Egor Pasko's avatar Egor Pasko Committed by Commit Bot

copy_ex.py: allow overwriting non-writable files

Since shutil.copy() fails when it cannot open(2) O_WRONLY the destination,
introduce an additional step: for a destination that is a file with different
contents, delete the destination before copying.

Back story:

I noticed that in my tree quite a few files were not writeable. It was
probably a consequence of a past bug, not sure which one. I was running:

shell> build/android/gradle/generate_gradle.py --output-directory out/Debug

This caused 'permission denied' from shutil.copy() when it attempted to
open the file for writing.

One way to reproduce it right now is:

shell> cd out/Debug
shell> touch obj/third_party/netty4/netty_all_java__process_prebuilt-filtered.jar
shell> chmod u-w lib.java/third_party/netty4/netty-all-4.1.9.Final.jar
shell> build/android/gradle/generate_gradle.py --output-directory out/Debug

BUG=None

Change-Id: Ifaa16d52bb2c0e6af362401fc635a3e21f3d7214
Reviewed-on: https://chromium-review.googlesource.com/1146923Reviewed-by: default avatarJohn Budorick <jbudorick@google.com>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Egor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577253}
parent 4ed8d3b6
......@@ -35,8 +35,14 @@ def CopyFile(f, dest, deps):
dest = os.path.join(dest, os.path.basename(f))
deps.append(f)
if os.path.isfile(dest) and filecmp.cmp(dest, f, shallow=False):
if os.path.isfile(dest):
if filecmp.cmp(dest, f, shallow=False):
return
# The shutil.copy() below would fail if the file does not have write
# permissions. Deleting the file has similar costs to modifying the
# permissions.
os.unlink(dest)
shutil.copy(f, dest)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment