Skip to content

Commit 4d25dc4

Browse files
larsxschneidergitster
authored andcommitted
git-p4: check free space during streaming
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2176a5 commit 4d25dc4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

git-p4.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ def chdir(path, is_client_path=False):
104104
path = os.getcwd()
105105
os.environ['PWD'] = path
106106

107+
def calcDiskFree():
108+
"""Return free space in bytes on the disk of the given dirname."""
109+
if platform.system() == 'Windows':
110+
free_bytes = ctypes.c_ulonglong(0)
111+
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(os.getcwd()), None, None, ctypes.pointer(free_bytes))
112+
return free_bytes.value
113+
else:
114+
st = os.statvfs(os.getcwd())
115+
return st.f_bavail * st.f_frsize
116+
107117
def die(msg):
108118
if verbose:
109119
raise Exception(msg)
@@ -2263,6 +2273,14 @@ def streamP4FilesCb(self, marshalled):
22632273
if marshalled["code"] == "error":
22642274
if "data" in marshalled:
22652275
err = marshalled["data"].rstrip()
2276+
2277+
if not err and 'fileSize' in self.stream_file:
2278+
required_bytes = int((4 * int(self.stream_file["fileSize"])) - calcDiskFree())
2279+
if required_bytes > 0:
2280+
err = 'Not enough space left on %s! Free at least %i MB.' % (
2281+
os.getcwd(), required_bytes/1024/1024
2282+
)
2283+
22662284
if err:
22672285
f = None
22682286
if self.stream_have_file_info:

0 commit comments

Comments
 (0)