make `python build/vs_toolchain.py update` work a bit better on non-windows

It still early-exits on non-Windows, so no visible change yet.

BUG=495204

Review URL: https://codereview.chromium.org/1181943003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295807 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py
index c41ccc5..0a589ec 100755
--- a/win_toolchain/get_toolchain_if_necessary.py
+++ b/win_toolchain/get_toolchain_if_necessary.py
@@ -128,7 +128,7 @@
 def LooksLikeGoogler():
   """Checks for a USERDOMAIN environment variable of 'GOOGLE', which
   probably implies the current user is a Googler."""
-  return os.environ.get('USERDOMAIN').upper() == 'GOOGLE'
+  return os.environ.get('USERDOMAIN', '').upper() == 'GOOGLE'
 
 
 def CanAccessToolchainBucket():
@@ -190,6 +190,15 @@
   return temp_dir, target_path
 
 
+def RmDir(path):
+  """Deletes path and all the files it contains."""
+  if sys.platform != 'win32':
+    shutil.rmtree(path, ignore_errors=True)
+  else:
+    # shutil.rmtree() doesn't delete read-only files on Windows.
+    subprocess.check_call('rmdir /s/q "%s"' % path, shell=True)
+
+
 def DoTreeMirror(target_dir, tree_sha1):
   """In order to save temporary space on bots that do not have enough space to
   download ISOs, unpack them, and copy to the target location, the whole tree
@@ -200,7 +209,7 @@
   with zipfile.ZipFile(local_zip, 'r', zipfile.ZIP_DEFLATED, True) as zf:
     zf.extractall(target_dir)
   if temp_dir:
-    subprocess.check_call('rmdir /s/q "%s"' % temp_dir, shell=True)
+    RmDir(temp_dir)
 
 
 def main():
@@ -222,6 +231,7 @@
       cmd.extend(['--output-json', winpath(options.output_json)])
     cmd.extend(args)
     sys.exit(subprocess.call(cmd))
+  assert sys.platform != 'cygwin'
 
   # We assume that the Pro hash is the first one.
   desired_hashes = args
@@ -263,12 +273,13 @@
     print('  desired_hashes: %s' % ', '.join(desired_hashes))
     sys.stdout.flush()
     DelayBeforeRemoving(target_dir)
-    # This stays resident and will make the rmdir below fail.
-    with open(os.devnull, 'wb') as nul:
-      subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'],
-                      stdin=nul, stdout=nul, stderr=nul)
+    if sys.platform == 'win32':
+      # This stays resident and will make the rmdir below fail.
+      with open(os.devnull, 'wb') as nul:
+        subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'],
+                        stdin=nul, stdout=nul, stderr=nul)
     if os.path.isdir(target_dir):
-      subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True)
+      RmDir(target_dir)
 
     DoTreeMirror(target_dir, desired_hashes[0])