Skip to content

Commit ae032d6

Browse files
committed
Drop our custom stat functions in favor of python's
Python added support for nanosecond timestamps in 3.3, so we shouldn't need our C *stat helpers anymore. Signed-off-by: Rob Browning <rlb@defaultvalue.org> Tested-by: Rob Browning <rlb@defaultvalue.org>
1 parent 71f5dda commit ae032d6

3 files changed

Lines changed: 15 additions & 146 deletions

File tree

‎configure‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -360,31 +360,6 @@ if test "${c_define[BUP_HAVE_READLINE]:-}"; then
360360
fi
361361
fi
362362

363-
info -n 'checking for ns resolution stat times'
364-
stat_code='
365-
#include <sys/stat.h>
366-
367-
int main(int argc, char **argv)
368-
{
369-
struct stat st;
370-
stat(argv[0], &st);
371-
return (int) st.BUP_TIME_FIELD;
372-
}
373-
'
374-
if try-c-code -DBUP_TIME_FIELD=st_atim.tv_nsec -- "$stat_code"; then
375-
info ' (found, tim)'
376-
c_define[BUP_STAT_NS_FLAVOR_TIM]=1
377-
elif try-c-code -DBUP_TIME_FIELD=st_atimensec.tv_nsec -- "$stat_code"; then
378-
info ' (found, timensec)'
379-
c_define[BUP_STAT_NS_FLAVOR_TIMENSEC]=1
380-
elif try-c-code -DBUP_TIME_FIELD=st_atimespec.tv_nsec -- "$stat_code"; then
381-
info ' (found, timespec)'
382-
c_define[BUP_STAT_NS_FLAVOR_TIMESPEC]=1
383-
else
384-
info ' (not found)'
385-
c_define[BUP_STAT_NS_FLAVOR_NONE]=1
386-
fi
387-
388363
info -n 'checking for tm tm_gmtoff field'
389364
if try-c-code \
390365
-- \

‎lib/bup/_helpers.c‎

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,100 +1093,6 @@ static PyObject *bup_set_linux_file_attr(PyObject *self, PyObject *args)
10931093
#endif /* def BUP_HAVE_FILE_ATTRS */
10941094

10951095

1096-
#ifdef BUP_STAT_NS_FLAVOR_TIM
1097-
# define BUP_STAT_ATIME_NS(st) (st)->st_atim.tv_nsec
1098-
# define BUP_STAT_MTIME_NS(st) (st)->st_mtim.tv_nsec
1099-
# define BUP_STAT_CTIME_NS(st) (st)->st_ctim.tv_nsec
1100-
#elif defined BUP_STAT_NS_FLAVOR_TIMENSEC
1101-
# define BUP_STAT_ATIME_NS(st) (st)->st_atimensec.tv_nsec
1102-
# define BUP_STAT_MTIME_NS(st) (st)->st_mtimensec.tv_nsec
1103-
# define BUP_STAT_CTIME_NS(st) (st)->st_ctimensec.tv_nsec
1104-
#elif defined BUP_STAT_NS_FLAVOR_TIMESPEC
1105-
# define BUP_STAT_ATIME_NS(st) (st)->st_atimespec.tv_nsec
1106-
# define BUP_STAT_MTIME_NS(st) (st)->st_mtimespec.tv_nsec
1107-
# define BUP_STAT_CTIME_NS(st) (st)->st_ctimespec.tv_nsec
1108-
#elif defined BUP_STAT_NS_FLAVOR_NONE
1109-
# define BUP_STAT_ATIME_NS(st) 0
1110-
# define BUP_STAT_MTIME_NS(st) 0
1111-
# define BUP_STAT_CTIME_NS(st) 0
1112-
#else
1113-
# error "./configure did not define a BUP_STAT_NS_FLAVOR"
1114-
#endif
1115-
1116-
1117-
static PyObject *stat_struct_to_py(const struct stat *st,
1118-
const char *filename,
1119-
int fd)
1120-
{
1121-
// We can check the known (via POSIX) signed and unsigned types at
1122-
// compile time, but not (easily) the unspecified types, so handle
1123-
// those via BUP_LONGISH_TO_PY(). Assumes ns values will fit in a
1124-
// long.
1125-
return Py_BuildValue("NKNNNNNL(Nl)(Nl)(Nl)",
1126-
BUP_LONGISH_TO_PY(st->st_mode),
1127-
(unsigned PY_LONG_LONG) st->st_ino,
1128-
BUP_LONGISH_TO_PY(st->st_dev),
1129-
BUP_LONGISH_TO_PY(st->st_nlink),
1130-
BUP_LONGISH_TO_PY(st->st_uid),
1131-
BUP_LONGISH_TO_PY(st->st_gid),
1132-
BUP_LONGISH_TO_PY(st->st_rdev),
1133-
(PY_LONG_LONG) st->st_size,
1134-
BUP_LONGISH_TO_PY(st->st_atime),
1135-
(long) BUP_STAT_ATIME_NS(st),
1136-
BUP_LONGISH_TO_PY(st->st_mtime),
1137-
(long) BUP_STAT_MTIME_NS(st),
1138-
BUP_LONGISH_TO_PY(st->st_ctime),
1139-
(long) BUP_STAT_CTIME_NS(st));
1140-
}
1141-
1142-
1143-
static PyObject *bup_stat(PyObject *self, PyObject *args)
1144-
{
1145-
int rc;
1146-
char *filename;
1147-
1148-
if (!PyArg_ParseTuple(args, cstr_argf, &filename))
1149-
return NULL;
1150-
1151-
struct stat st;
1152-
rc = stat(filename, &st);
1153-
if (rc != 0)
1154-
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
1155-
return stat_struct_to_py(&st, filename, 0);
1156-
}
1157-
1158-
1159-
static PyObject *bup_lstat(PyObject *self, PyObject *args)
1160-
{
1161-
int rc;
1162-
char *filename;
1163-
1164-
if (!PyArg_ParseTuple(args, cstr_argf, &filename))
1165-
return NULL;
1166-
1167-
struct stat st;
1168-
rc = lstat(filename, &st);
1169-
if (rc != 0)
1170-
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
1171-
return stat_struct_to_py(&st, filename, 0);
1172-
}
1173-
1174-
1175-
static PyObject *bup_fstat(PyObject *self, PyObject *args)
1176-
{
1177-
int rc, fd;
1178-
1179-
if (!PyArg_ParseTuple(args, "i", &fd))
1180-
return NULL;
1181-
1182-
struct stat st;
1183-
rc = fstat(fd, &st);
1184-
if (rc != 0)
1185-
return PyErr_SetFromErrno(PyExc_OSError);
1186-
return stat_struct_to_py(&st, NULL, fd);
1187-
}
1188-
1189-
11901096
#ifdef HAVE_TM_TM_GMTOFF
11911097
static PyObject *bup_localtime(PyObject *self, PyObject *args)
11921098
{
@@ -1913,12 +1819,6 @@ static PyMethodDef helper_methods[] = {
19131819
{ "set_linux_file_attr", bup_set_linux_file_attr, METH_VARARGS,
19141820
"Set the Linux attributes for the given file." },
19151821
#endif
1916-
{ "stat", bup_stat, METH_VARARGS,
1917-
"Extended version of stat." },
1918-
{ "lstat", bup_lstat, METH_VARARGS,
1919-
"Extended version of lstat." },
1920-
{ "fstat", bup_fstat, METH_VARARGS,
1921-
"Extended version of fstat." },
19221822
#ifdef HAVE_TM_TM_GMTOFF
19231823
{ "localtime", bup_localtime, METH_VARARGS,
19241824
"Return struct_time elements plus the timezone offset and name." },

‎lib/bup/xstat.py‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import os, sys, time
55
import stat as pystat
66

7-
from bup import _helpers
8-
97

108
def timespec_to_nsecs(ts):
119
ts_s, ts_ns = ts
@@ -64,40 +62,36 @@ class stat_result:
6462
__slots__ = ('st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid', 'st_gid',
6563
'st_rdev', 'st_size', 'st_atime', 'st_mtime', 'st_ctime')
6664
@staticmethod
67-
def from_xstat_rep(st):
68-
global _cygwin_sys
65+
def from_py_stat(st):
6966
result = stat_result()
70-
(result.st_mode,
71-
result.st_ino,
72-
result.st_dev,
73-
result.st_nlink,
74-
result.st_uid,
75-
result.st_gid,
76-
result.st_rdev,
77-
result.st_size,
78-
result.st_atime,
79-
result.st_mtime,
80-
result.st_ctime) = st
67+
result.st_mode = st.st_mode
68+
result.st_ino = st.st_ino
69+
result.st_dev = st.st_dev
70+
result.st_nlink = st.st_nlink
71+
result.st_uid = st.st_uid
72+
result.st_gid = st.st_gid
73+
result.st_rdev = st.st_rdev
74+
result.st_size = st.st_size
8175
# Inlined timespec_to_nsecs after profiling
82-
result.st_atime = result.st_atime[0] * 10**9 + result.st_atime[1]
83-
result.st_mtime = result.st_mtime[0] * 10**9 + result.st_mtime[1]
84-
result.st_ctime = result.st_ctime[0] * 10**9 + result.st_ctime[1]
76+
result.st_atime = st.st_atime_ns
77+
result.st_mtime = st.st_mtime_ns
78+
result.st_ctime = st.st_ctime_ns
8579
if _cygwin_sys:
8680
result.st_uid = _fix_cygwin_id(result.st_uid)
8781
result.st_gid = _fix_cygwin_id(result.st_gid)
8882
return result
8983

9084

9185
def stat(path):
92-
return stat_result.from_xstat_rep(_helpers.stat(path))
86+
return stat_result.from_py_stat(os.stat(path))
9387

9488

9589
def fstat(path):
96-
return stat_result.from_xstat_rep(_helpers.fstat(path))
90+
return stat_result.from_py_stat(os.fstat(path))
9791

9892

9993
def lstat(path):
100-
return stat_result.from_xstat_rep(_helpers.lstat(path))
94+
return stat_result.from_py_stat(os.lstat(path))
10195

10296

10397
def mode_str(mode):

0 commit comments

Comments
 (0)