mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont use win32 API function to make long paths useable as it fails on older windows
This commit is contained in:
parent
748152cd7a
commit
758f3e1452
@ -141,7 +141,7 @@
|
||||
"only": "windows",
|
||||
"headers": "calibre/utils/windows/common.h",
|
||||
"sources": "calibre/utils/windows/winutil.cpp",
|
||||
"libraries": "shell32 wininet advapi32 Pathcch",
|
||||
"libraries": "shell32 wininet advapi32",
|
||||
"cflags": "/X"
|
||||
},
|
||||
{
|
||||
|
@ -261,8 +261,6 @@ class BuildTest(unittest.TestCase):
|
||||
self.assertRaises(OSError, winutil.create_mutex, 'test-mutex', False)
|
||||
m.close()
|
||||
self.assertEqual(winutil.parse_cmdline('"c:\\test exe.exe" "some arg" 2'), ('c:\\test exe.exe', 'some arg', '2'))
|
||||
q = 'c:/hello/{}.txt'.format('a' * 400)
|
||||
self.assertEqual(winutil.canonicalize_path(q), '\\\\?\\' + q)
|
||||
|
||||
def test_sqlite(self):
|
||||
import sqlite3
|
||||
|
@ -595,10 +595,11 @@ rmtree = shutil.rmtree
|
||||
|
||||
|
||||
if iswindows:
|
||||
long_path_prefix = '\\\\?\\'
|
||||
|
||||
def make_long_path_useable(path):
|
||||
if len(path) > 200:
|
||||
from calibre_extensions.winutil import canonicalize_path
|
||||
path = canonicalize_path(path)
|
||||
if len(path) > 200 and os.path.isabs(path) and not path.startswith(long_path_prefix):
|
||||
path = long_path_prefix + os.path.normpath(path)
|
||||
return path
|
||||
else:
|
||||
def make_long_path_useable(path):
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <shlguid.h>
|
||||
#include <shellapi.h>
|
||||
#include <shlwapi.h>
|
||||
#include <pathcch.h>
|
||||
#include <commoncontrols.h>
|
||||
#include <comip.h>
|
||||
#include <comdef.h>
|
||||
@ -725,24 +724,6 @@ get_long_path_name(PyObject *self, PyObject *args) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
canonicalize_path(PyObject *self, PyObject *args) {
|
||||
wchar_raii path;
|
||||
if (!PyArg_ParseTuple(args, "O&", py_to_wchar_no_none, &path)) return NULL;
|
||||
size_t path_len = 0;
|
||||
wchar_t *p = path.ptr();
|
||||
while (p[path_len]) {
|
||||
if (p[path_len] == '/') p[path_len] = '\\';
|
||||
path_len++;
|
||||
}
|
||||
wchar_t *ans;
|
||||
HRESULT hr = PathAllocCanonicalize(p, PATHCCH_ENSURE_IS_EXTENDED_LENGTH_PATH, &ans);
|
||||
if (FAILED(hr)) return error_from_hresult(hr, "Failed to canonicalize path", PyTuple_GET_ITEM(args, 0));
|
||||
PyObject *r = PyUnicode_FromWideChar(ans, -1);
|
||||
LocalFree(ans);
|
||||
return r;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_process_times(PyObject *self, PyObject *pid) {
|
||||
HANDLE h = INVALID_HANDLE_VALUE;
|
||||
@ -1025,7 +1006,6 @@ static PyMethodDef winutil_methods[] = {
|
||||
M(set_handle_information, METH_VARARGS),
|
||||
M(get_long_path_name, METH_VARARGS),
|
||||
M(get_process_times, METH_O),
|
||||
M(canonicalize_path, METH_VARARGS),
|
||||
M(get_handle_information, METH_VARARGS),
|
||||
M(get_last_error, METH_NOARGS),
|
||||
M(load_library, METH_VARARGS),
|
||||
|
Loading…
x
Reference in New Issue
Block a user