mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Port os.rename calls to work on Windows
os.rename fails on Windows if the destination exists, so replace os.rename to platform_utils.rename which handles the platform differences. Change-Id: I15a86f10f65eedee5b003b80f88a0c28a3e1aa48
This commit is contained in:
parent
a65adf74f9
commit
ad1abcb556
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import errno
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import select
|
import select
|
||||||
@ -225,3 +226,19 @@ def handle_rmtree_error(function, path, excinfo):
|
|||||||
# Allow deleting read-only files
|
# Allow deleting read-only files
|
||||||
os.chmod(path, stat.S_IWRITE)
|
os.chmod(path, stat.S_IWRITE)
|
||||||
function(path)
|
function(path)
|
||||||
|
|
||||||
|
|
||||||
|
def rename(src, dst):
|
||||||
|
if isWindows():
|
||||||
|
# On Windows, rename fails if destination exists, see
|
||||||
|
# https://docs.python.org/2/library/os.html#os.rename
|
||||||
|
try:
|
||||||
|
os.rename(src, dst)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == errno.EEXIST:
|
||||||
|
os.remove(dst)
|
||||||
|
os.rename(src, dst)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
os.rename(src, dst)
|
||||||
|
@ -63,7 +63,7 @@ def _lwrite(path, content):
|
|||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.rename(lock, path)
|
platform_utils.rename(lock, path)
|
||||||
except OSError:
|
except OSError:
|
||||||
os.remove(lock)
|
os.remove(lock)
|
||||||
raise
|
raise
|
||||||
@ -2198,7 +2198,7 @@ class Project(object):
|
|||||||
|
|
||||||
if os.path.exists(tmpPath):
|
if os.path.exists(tmpPath):
|
||||||
if curlret == 0 and self._IsValidBundle(tmpPath, quiet):
|
if curlret == 0 and self._IsValidBundle(tmpPath, quiet):
|
||||||
os.rename(tmpPath, dstPath)
|
platform_utils.rename(tmpPath, dstPath)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
os.remove(tmpPath)
|
os.remove(tmpPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user