From 0fa507a782ee2694a30ed3fbe82648e1b30a88f8 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 20 May 2009 16:42:17 +0000 Subject: [PATCH] mmap.mmap works differently under windows --- osc/core.py | 6 ++++-- osc/util/ar.py | 5 ++++- osc/util/cpio.py | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/osc/core.py b/osc/core.py index 6c0368e9..509a7505 100755 --- a/osc/core.py +++ b/osc/core.py @@ -1536,8 +1536,10 @@ def http_request(method, url, headers={}, data=None, file=None, timeout=100): import mmap filefd = open(file, 'r') try: - data = mmap.mmap(filefd.fileno(), os.path.getsize(file), - mmap.MAP_SHARED, mmap.PROT_READ) + if sys.platform[:3] != 'win': + data = mmap.mmap(filefd.fileno(), os.path.getsize(file), mmap.MAP_SHARED, mmap.PROT_READ) + else: + data = mmap.mmap(filefd.fileno(), os.path.getsize(file)) data = buffer(data) except EnvironmentError, e: if e.errno == 19: diff --git a/osc/util/ar.py b/osc/util/ar.py index 4ed5dbb3..ae551513 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -147,7 +147,10 @@ class Ar: import mmap self.__file = open(self.filename, 'rb') try: - self.__file = mmap.mmap(self.__file.fileno(), 0, prot=mmap.PROT_READ) + if sys.platform[:3] != 'win': + self.__file = mmap.mmap(self.__file.fileno(), 0, prot=mmap.PROT_READ) + else: + self.__file = mmap.mmap(self.__file.fileno(), 0) except EnvironmentError, e: if e.errno == 19: print >>sys.stderr, 'cannot use mmap to read the file, falling back to the default io' diff --git a/osc/util/cpio.py b/osc/util/cpio.py index 340f979a..9e856a89 100644 --- a/osc/util/cpio.py +++ b/osc/util/cpio.py @@ -17,6 +17,7 @@ import mmap import os import stat import struct +import sys # format implementation is based on src/copyin.c and src/util.c (see cpio sources) @@ -139,7 +140,10 @@ class Cpio: if not self.__file: self.__file = open(self.filename, 'rb') try: - self.__file = mmap.mmap(self.__file.fileno(), 0, prot = mmap.PROT_READ) + if sys.platform[:3] != 'win': + self.__file = mmap.mmap(self.__file.fileno(), 0, prot = mmap.PROT_READ) + else: + self.__file = mmap.mmap(self.__file.fileno(), 0) except EnvironmentError, e: if e.errno == 19: print >>sys.stderr, 'cannot use mmap to read the file, failing back to default'