-
+#define _LARGEFILE64_SOURCE 1
+ #undef NDEBUG
#include "bupsplit.h"
#include <Python.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
+#ifdef linux
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#endif
+
static int istty = 0;
+ // Probably we should use autoconf or something and set HAVE_PY_GETARGCARGV...
+ #if __WIN32__ || __CYGWIN__
+
+ // There's no 'ps' on win32 anyway, and Py_GetArgcArgv() isn't available.
+ static void unpythonize_argv(void) { }
+
+ #else // not __WIN32__
+
+ // For some reason this isn't declared in Python.h
+ extern void Py_GetArgcArgv(int *argc, char ***argv);
+
+ static void unpythonize_argv(void)
+ {
+ int argc, i;
+ char **argv, *arge;
+
+ Py_GetArgcArgv(&argc, &argv);
+
+ for (i = 0; i < argc-1; i++)
+ {
+ if (argv[i] + strlen(argv[i]) + 1 != argv[i+1])
+ {
+ // The argv block doesn't work the way we expected; it's unsafe
+ // to mess with it.
+ return;
+ }
+ }
+
+ arge = argv[argc-1] + strlen(argv[argc-1]) + 1;
+
+ if (strstr(argv[0], "python") && argv[1] == argv[0] + strlen(argv[0]) + 1)
+ {
+ char *p;
+ size_t len, diff;
+ p = strrchr(argv[1], '/');
+ if (p)
+ {
+ p++;
+ diff = p - argv[0];
+ len = arge - p;
+ memmove(argv[0], p, len);
+ memset(arge - diff, 0, diff);
+ for (i = 0; i < argc; i++)
+ argv[i] = argv[i+1] ? argv[i+1]-diff : NULL;
+ }
+ }
+ }
+
+ #endif // not __WIN32__ or __CYGWIN__
+
+
static PyObject *selftest(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
{ NULL, NULL, 0, NULL }, // sentinel
};
+
PyMODINIT_FUNC init_helpers(void)
{
- Py_InitModule("_helpers", faster_methods);
+ PyObject *m = Py_InitModule("_helpers", faster_methods);
+ if (m == NULL)
+ return;
+#ifdef HAVE_BUP_UTIMENSAT
+ PyModule_AddObject(m, "AT_FDCWD", Py_BuildValue("i", AT_FDCWD));
+ PyModule_AddObject(m, "AT_SYMLINK_NOFOLLOW",
+ Py_BuildValue("i", AT_SYMLINK_NOFOLLOW));
+#endif
+#ifdef HAVE_BUP_STAT
+ Py_INCREF(Py_True);
+ PyModule_AddObject(m, "_have_ns_fs_timestamps", Py_True);
+#else
+ Py_INCREF(Py_False);
+ PyModule_AddObject(m, "_have_ns_fs_timestamps", Py_False);
+#endif
istty = isatty(2) || getenv("BUP_FORCE_TTY");
+ unpythonize_argv();
}
"""Helper functions and classes for bup."""
import sys, os, pwd, subprocess, errno, socket, select, mmap, stat, re, struct
- import heapq, operator
- from bup import _version
+ import heapq, operator, time
+ from bup import _version, _helpers
+import bup._helpers as _helpers
# This function should really be in helpers, not in bup.options. But we
# want options.py to be standalone so people can include it in other projects.
log('%-70s\n' % e)
- istty = os.isatty(2) or atoi(os.environ.get('BUP_FORCE_TTY'))
- def progress(s):
- """Calls log(s) if stderr is a TTY. Does nothing otherwise."""
- if istty:
- log(s)
-
-
+def clear_errors():
+ global saved_errors
+ saved_errors = []
+
+
def handle_ctrl_c():
"""Replace the default exception handler for KeyboardInterrupt (Ctrl-C).