Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 867029, Port windows clobberer fixes to purge_builds.py (unable t…
Browse files Browse the repository at this point in the history
…o free enough space), r=jhopkins
  • Loading branch information
nthomas-mozilla committed Apr 30, 2013
1 parent 15c36d0 commit 36b43fb
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions buildfarm/maintenance/purge_builds.py
Expand Up @@ -30,10 +30,13 @@

if sys.platform == 'win32':
# os.statvfs doesn't work on Windows
import win32file
from win32file import RemoveDirectory, DeleteFile, \
GetFileAttributesW, SetFileAttributesW, GetDiskFreeSpace, \
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_DIRECTORY
from win32api import FindFiles

def freespace(p):
secsPerClus, bytesPerSec, nFreeClus, totClus = win32file.GetDiskFreeSpace(p)
secsPerClus, bytesPerSec, nFreeClus, totClus = GetDiskFreeSpace(p)
return secsPerClus * bytesPerSec * nFreeClus
else:
def freespace(p):
Expand All @@ -47,10 +50,38 @@ def mtime_sort(p1, p2):
return cmp(os.path.getmtime(p1), os.path.getmtime(p2))


def rmdirRecursiveWindows(dir):
"""Windows-specific version of rmdirRecursive that handles
path lengths longer than MAX_PATH.
"""

dir = os.path.realpath(dir)
# Make sure directory is writable
SetFileAttributesW('\\\\?\\' + dir, FILE_ATTRIBUTE_NORMAL)

for ffrec in FindFiles('\\\\?\\' + dir + '\*.*'):
file_attr = ffrec[0]
name = ffrec[8]
if name == '.' or name == '..':
continue
full_name = os.path.join(dir, name)

if file_attr & FILE_ATTRIBUTE_DIRECTORY:
rmdirRecursiveWindows(full_name)
else:
SetFileAttributesW('\\\\?\\' + full_name, FILE_ATTRIBUTE_NORMAL)
DeleteFile('\\\\?\\' + full_name)
RemoveDirectory('\\\\?\\' + dir)


def rmdirRecursive(dir):
"""This is a replacement for shutil.rmtree that works better under
windows. Thanks to Bear at the OSAF for the code.
(Borrowed from buildbot.slave.commands)"""
if os.name == 'nt':
rmdirRecursiveWindows(dir)
return

if not os.path.exists(dir):
# This handles broken links
if os.path.islink(dir):
Expand Down

0 comments on commit 36b43fb

Please sign in to comment.