Fix "Load/Save to cloudstorage" for non-ASCII user names

On Windows that would fail because stat() doesn't deal well with our
utf8 strings.

Added new subsurface_stat() portability function to replace stat().
Added Windows implementation of subsurface_stat() using wstat(),
with conversion to ut16 of the inputed path.
Other platform implementations (linux, android) make use of the normal stat().

Added non ASCII test case in TestGitStorage::testGitStorageLocal()

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
This commit is contained in:
Jeremie Guichard 2017-02-24 14:06:48 +07:00 committed by Dirk Hohndel
parent 5640a6a839
commit 5ed93a9d9e
6 changed files with 27 additions and 2 deletions

View file

@ -176,6 +176,11 @@ int subsurface_access(const char *path, int mode)
return access(path, mode); return access(path, mode);
} }
int subsurface_stat(const char* path, struct stat* buf)
{
return stat(path, buf);
}
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp) struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
{ {
return zip_open(path, flags, errorp); return zip_open(path, flags, errorp);

View file

@ -8,6 +8,7 @@
#include <zip.h> #include <zip.h>
#include <sqlite3.h> #include <sqlite3.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include "divesite.h" #include "divesite.h"
/* Windows has no MIN/MAX macros - so let's just roll our own */ /* Windows has no MIN/MAX macros - so let's just roll our own */
@ -728,6 +729,7 @@ extern int subsurface_open(const char *path, int oflags, mode_t mode);
extern FILE *subsurface_fopen(const char *path, const char *mode); extern FILE *subsurface_fopen(const char *path, const char *mode);
extern void *subsurface_opendir(const char *path); extern void *subsurface_opendir(const char *path);
extern int subsurface_access(const char *path, int mode); extern int subsurface_access(const char *path, int mode);
extern int subsurface_stat(const char* path, struct stat* buf);
extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp); extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp);
extern int subsurface_zip_close(struct zip *zip); extern int subsurface_zip_close(struct zip *zip);
extern void subsurface_console_init(bool dedicated, bool logfile); extern void subsurface_console_init(bool dedicated, bool logfile);

View file

@ -768,7 +768,7 @@ static struct git_repository *get_remote_repo(const char *localdir, const char *
} }
git_storage_update_progress(false, "start git interaction"); git_storage_update_progress(false, "start git interaction");
/* Do we already have a local cache? */ /* Do we already have a local cache? */
if (!stat(localdir, &st)) { if (!subsurface_stat(localdir, &st)) {
if (!S_ISDIR(st.st_mode)) { if (!S_ISDIR(st.st_mode)) {
if (is_subsurface_cloud) if (is_subsurface_cloud)
(void)cleanup_local_cache(remote, branch); (void)cleanup_local_cache(remote, branch);
@ -934,7 +934,7 @@ struct git_repository *is_git_repository(const char *filename, const char **bran
return repo; return repo;
} }
if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) { if (subsurface_stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) {
free(loc); free(loc);
free(branch); free(branch);
return dummy_git_repository; return dummy_git_repository;

View file

@ -204,6 +204,11 @@ int subsurface_access(const char *path, int mode)
return access(path, mode); return access(path, mode);
} }
int subsurface_stat(const char* path, struct stat* buf)
{
return stat(path, buf);
}
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp) struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
{ {
return zip_open(path, flags, errorp); return zip_open(path, flags, errorp);

View file

@ -346,6 +346,18 @@ int subsurface_access(const char *path, int mode)
return ret; return ret;
} }
int subsurface_stat(const char* path, struct stat* buf)
{
int ret = -1;
if (!path)
return ret;
wchar_t *wpath = utf8_to_utf16(path);
if (wpath)
ret = wstat(wpath, buf);
free((void *)wpath);
return ret;
}
#ifndef O_BINARY #ifndef O_BINARY
#define O_BINARY 0 #define O_BINARY 0
#endif #endif

View file

@ -64,6 +64,7 @@ void TestGitStorage::testGitStorageLocal_data()
// test different path we may encounter (since storage depends on user name) // test different path we may encounter (since storage depends on user name)
QTest::addColumn<QString>("testDirName"); QTest::addColumn<QString>("testDirName");
QTest::newRow("ASCII path") << "./gittest"; QTest::newRow("ASCII path") << "./gittest";
QTest::newRow("Non ASCII path") << "./gittest_éèêôàüäößíñóúäåöø";
} }
void TestGitStorage::testGitStorageLocal() void TestGitStorage::testGitStorageLocal()