Index: client/isolateserver.py |
diff --git a/client/isolateserver.py b/client/isolateserver.py |
index bde5fc89f8cc46a88e3360841a7df30e6c5d0f15..e4877c4bee500294eae9e4fcaac3ce7f37192ac3 100755 |
--- a/client/isolateserver.py |
+++ b/client/isolateserver.py |
@@ -9,6 +9,7 @@ __version__ = '0.4.8' |
import base64 |
import functools |
+import errno |
import logging |
import optparse |
import os |
@@ -19,8 +20,6 @@ import tempfile |
import threading |
import time |
import types |
-import urllib |
-import urlparse |
import zlib |
from third_party import colorama |
@@ -116,6 +115,10 @@ class Aborted(Error): |
pass |
+class AlreadyExists(Error): |
+ """File already exists.""" |
+ |
+ |
def file_read(path, chunk_size=isolated_format.DISK_FILE_CHUNK, offset=0): |
"""Yields file content in chunks of |chunk_size| starting from |offset|.""" |
with fs.open(path, 'rb') as f: |
@@ -221,8 +224,12 @@ def create_symlinks(base_directory, files): |
logging.warning('Ignoring symlink %s', filepath) |
continue |
outfile = os.path.join(base_directory, filepath) |
- # os.symlink() doesn't exist on Windows. |
- os.symlink(properties['l'], outfile) # pylint: disable=E1101 |
+ try: |
+ os.symlink(properties['l'], outfile) # pylint: disable=E1101 |
+ except OSError as e: |
+ if e.errno == errno.EEXIST: |
+ raise AlreadyExists('File %s already exists.' % outfile) |
+ raise |
def is_valid_file(path, size): |
@@ -1967,8 +1974,10 @@ def fetch_isolated(isolated_hash, storage, cache, outdir): |
# Link corresponding files to a fetched item in cache. |
for filepath, props in remaining.pop(digest): |
- cache.hardlink( |
- digest, os.path.join(outdir, filepath), props.get('m')) |
+ dest = os.path.join(outdir, filepath) |
+ if os.path.exists(dest): |
+ raise AlreadyExists('File %s already exists' % dest) |
+ cache.hardlink(digest, dest, props.get('m')) |
# Report progress. |
duration = time.time() - last_update |