Lines 939-948
Link Here
|
939 |
if not fcmd: |
939 |
if not fcmd: |
940 |
raise EnvironmentError("FETCHCOMMAND is unset") |
940 |
raise EnvironmentError("FETCHCOMMAND is unset") |
941 |
|
941 |
|
942 |
fd, tmp_filename = tempfile.mkstemp() |
942 |
# old method completely breaks timestamp caching |
943 |
tmp_dirname, tmp_basename = os.path.split(tmp_filename) |
943 |
# make a secure archive copy of our file (preserves timestamps) |
944 |
os.close(fd) |
944 |
# cd to tempdir so wget analyses the unqualified basename |
|
|
945 |
# fetch file |
946 |
# cd back |
947 |
tmp_dirname = tempfile.mkdtemp() |
948 |
fetch_cwd = os.getcwd() |
949 |
os.chdir(tmp_dirname) |
950 |
tmp_basename = os.path.basename(pkgindex_file) |
945 |
|
951 |
|
|
|
952 |
# no race condition since the target is atomically unlinked if exists |
953 |
fd_tmpfile,tmp_filename = tempfile.mkstemp(dir=tmp_dirname) |
954 |
os.rename(tmp_filename, tmp_basename) |
955 |
f_tmpfile = os.fdopen(fd_tmpfile, 'wb') |
956 |
|
957 |
# copy original file |
958 |
f_pkgindex_file = open(pkgindex_file, 'rb') |
959 |
f_tmpfile.write(f_pkgindex_file.read()) |
960 |
f_tmpfile.close() |
961 |
f_pkgindex_file.close() |
962 |
|
963 |
# preserve timestamps |
964 |
os.utime(tmp_basename, (int(local_timestamp), int(local_timestamp))) |
965 |
tmp_stat_original = os.stat(tmp_basename) |
966 |
|
967 |
fcmd = fcmd.replace('-O "${DISTDIR}/${FILE}"', '-N') |
968 |
|
946 |
fcmd_vars = { |
969 |
fcmd_vars = { |
947 |
"DISTDIR": tmp_dirname, |
970 |
"DISTDIR": tmp_dirname, |
948 |
"FILE": tmp_basename, |
971 |
"FILE": tmp_basename, |
Lines 957-965
Link Here
|
957 |
|
980 |
|
958 |
success = portage.getbinpkg.file_get( |
981 |
success = portage.getbinpkg.file_get( |
959 |
fcmd=fcmd, fcmd_vars=fcmd_vars) |
982 |
fcmd=fcmd, fcmd_vars=fcmd_vars) |
|
|
983 |
|
984 |
# return from whence we came, cleanups? |
985 |
os.chdir(fetch_cwd) |
986 |
if tmp_stat_original.st_ctime == os.stat(os.path.join(tmp_dirname, tmp_basename)).st_ctime: |
987 |
# set to the tmpdir so both are deleted |
988 |
tmp_filename = tmp_dirname |
989 |
raise UseCachedCopyOfRemoteIndex() |
990 |
|
960 |
if not success: |
991 |
if not success: |
961 |
raise EnvironmentError("%s failed" % (setting,)) |
992 |
raise EnvironmentError("%s failed" % (setting,)) |
962 |
f = open(tmp_filename, 'rb') |
993 |
f = open(tmp_basename, 'rb') |
|
|
994 |
# set to the tmpdir so both are deleted |
995 |
tmp_filename = tmp_dirname |
963 |
|
996 |
|
964 |
f_dec = codecs.iterdecode(f, |
997 |
f_dec = codecs.iterdecode(f, |
965 |
_encodings['repo.content'], errors='replace') |
998 |
_encodings['repo.content'], errors='replace') |