Skip to content

Commit

Permalink
git-p4: check free space during streaming
Browse files Browse the repository at this point in the history
git-p4 will just halt if there is not enough disk space while
streaming content from P4 to Git. Add a check to ensure at least
4 times (arbitrarily chosen) the size of a streamed file is available.

Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Lars Schneider authored and Junio C Hamano committed Oct 3, 2015
1 parent d2176a5 commit 4d25dc4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def chdir(path, is_client_path=False):
path = os.getcwd()
os.environ['PWD'] = path

def calcDiskFree():
"""Return free space in bytes on the disk of the given dirname."""
if platform.system() == 'Windows':
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(os.getcwd()), None, None, ctypes.pointer(free_bytes))
return free_bytes.value
else:
st = os.statvfs(os.getcwd())
return st.f_bavail * st.f_frsize

def die(msg):
if verbose:
raise Exception(msg)
Expand Down Expand Up @@ -2263,6 +2273,14 @@ def streamP4FilesCb(self, marshalled):
if marshalled["code"] == "error":
if "data" in marshalled:
err = marshalled["data"].rstrip()

if not err and 'fileSize' in self.stream_file:
required_bytes = int((4 * int(self.stream_file["fileSize"])) - calcDiskFree())
if required_bytes > 0:
err = 'Not enough space left on %s! Free at least %i MB.' % (
os.getcwd(), required_bytes/1024/1024
)

if err:
f = None
if self.stream_have_file_info:
Expand Down

0 comments on commit 4d25dc4

Please sign in to comment.