From 744e10faf9136f91531280b86fd8c7fabe09bfed Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Wed, 23 Sep 2015 11:13:07 +0200 Subject: [PATCH] Print paths to internal files in verbose mode When run with -v option, this prints local file names like the path to the local git repository and the hash file. Signed-off-by: Robert C. Helling --- file.c | 2 +- git-access.c | 5 ++++- git-access.h | 4 ++-- main.cpp | 2 ++ qthelper.cpp | 34 ++++++++++++++++++++++++++++++---- qthelperfromc.h | 3 +++ save-xml.c | 2 +- subsurfacestartup.c | 19 +++++++++++++++++++ subsurfacestartup.h | 1 + 9 files changed, 63 insertions(+), 9 deletions(-) diff --git a/file.c b/file.c index a7a340f..f0f5423 100644 --- a/file.c +++ b/file.c @@ -436,7 +436,7 @@ int parse_file(const char *filename) char *fmt; int ret; - git = is_git_repository(filename, &branch, NULL); + git = is_git_repository(filename, &branch, NULL, false); if (prefs.cloud_git_url && strstr(filename, prefs.cloud_git_url) && git == dummy_git_repository) diff --git a/git-access.c b/git-access.c index cd371cf..43863f3 100644 --- a/git-access.c +++ b/git-access.c @@ -772,7 +772,7 @@ static struct git_repository *is_remote_git_repository(char *remote, const char /* * If it's not a git repo, return NULL. Be very conservative. */ -struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote) +struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote, bool dry_run) { int flen, blen, ret; int offset = 1; @@ -823,6 +823,9 @@ struct git_repository *is_git_repository(const char *filename, const char **bran return dummy_git_repository; } + if (dry_run) + return dummy_git_repository; + repo = is_remote_git_repository(loc, branch); if (repo) { if (remote) diff --git a/git-access.h b/git-access.h index beb764e..a2a9ba3 100644 --- a/git-access.h +++ b/git-access.h @@ -14,7 +14,7 @@ enum remote_transport { RT_OTHER, RT_HTTPS, RT_SSH }; struct git_oid; struct git_repository; #define dummy_git_repository ((git_repository *)3ul) /* Random bogus pointer, not NULL */ -extern struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote); +extern struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote, bool dry_run); extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch, enum remote_transport rt); extern int git_save_dives(struct git_repository *, const char *, const char *remote, bool select_only); extern int git_load_dives(struct git_repository *, const char *); @@ -23,7 +23,7 @@ extern const char *saved_git_id; extern void clear_git_id(void); extern void set_git_id(const struct git_oid *); void set_git_update_cb(int(*cb)(int)); - +char *get_local_dir(const char *remote, const char *branch); #ifdef __cplusplus } #endif diff --git a/main.cpp b/main.cpp index 747d2b2..c288f68 100644 --- a/main.cpp +++ b/main.cpp @@ -74,6 +74,8 @@ int main(int argc, char **argv) m->setLoadedWithFiles(!files.isEmpty() || !importedFiles.isEmpty()); m->loadFiles(files); m->importFiles(importedFiles); + if (verbose > 0) + print_files(); if (!quit) run_ui(); exit_ui(); diff --git a/qthelper.cpp b/qthelper.cpp index 6e3c957..255cd54 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1051,9 +1051,19 @@ extern "C" char * hashstring(char * filename) return hashOf[QString(filename)].toHex().data(); } +const QString hashfile_name() +{ + return QString(system_default_directory()).append("/hashes"); +} + +extern "C" char *hashfile_name_string() +{ + return strdup(hashfile_name().toUtf8().data()); +} + void read_hashes() { - QFile hashfile(QString(system_default_directory()).append("/hashes")); + QFile hashfile(hashfile_name()); if (hashfile.open(QIODevice::ReadOnly)) { QDataStream stream(&hashfile); stream >> localFilenameOf; @@ -1064,7 +1074,7 @@ void read_hashes() void write_hashes() { - QSaveFile hashfile(QString(system_default_directory()).append("/hashes")); + QSaveFile hashfile(hashfile_name()); if (hashfile.open(QIODevice::WriteOnly)) { QDataStream stream(&hashfile); stream << localFilenameOf; @@ -1183,13 +1193,22 @@ extern "C" bool picture_exists(struct picture *picture) return same_string(hash.toHex().data(), picture->hash); } +const QString picturedir() +{ + return QString(system_default_directory()).append("/picturedata/"); +} + +extern "C" char *picturedir_string() +{ + return strdup(picturedir().toUtf8().data()); +} + /* when we get a picture from git storage (local or remote) and can't find the picture * based on its hash, we create a local copy with the hash as filename and the appropriate * suffix */ extern "C" void savePictureLocal(struct picture *picture, const char *data, int len) { - QString dirname(system_default_directory()); - dirname += "/picturedata/"; + QString dirname = picturedir(); QDir localPictureDir(dirname); localPictureDir.mkpath(dirname); QString suffix(picture->filename); @@ -1358,6 +1377,13 @@ int getCloudURL(QString &filename) return 0; } +extern "C" char *cloud_url() +{ + QString filename; + getCloudURL(filename); + return strdup(filename.toUtf8().data()); +} + void loadPreferences() { QSettings s; diff --git a/qthelperfromc.h b/qthelperfromc.h index d64bfc0..7f64d7e 100644 --- a/qthelperfromc.h +++ b/qthelperfromc.h @@ -13,5 +13,8 @@ bool picture_exists(struct picture *picture); const char *local_file_path(struct picture *picture); void savePictureLocal(struct picture *picture, const char *data, int len); void cache_picture(struct picture *picture); +char *cloud_url(); +char *hashfile_name_string(); +char *picturedir_string(); #endif // QTHELPERFROMC_H diff --git a/save-xml.c b/save-xml.c index 6921e3b..25cf417 100644 --- a/save-xml.c +++ b/save-xml.c @@ -651,7 +651,7 @@ int save_dives_logic(const char *filename, const bool select_only) const char *branch, *remote; int error; - git = is_git_repository(filename, &branch, &remote); + git = is_git_repository(filename, &branch, &remote, false); if (git) return git_save_dives(git, branch, remote, select_only); diff --git a/subsurfacestartup.c b/subsurfacestartup.c index 18d00d3..7c03d60 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -3,6 +3,9 @@ #include #include #include "gettext.h" +#include "qthelperfromc.h" +#include "git-access.h" + struct preferences prefs, informational_prefs; struct preferences default_prefs = { .cloud_base_url = "https://cloud.subsurface-divelog.org/", @@ -134,6 +137,22 @@ static void print_version() printf("built with libdivecomputer v%s\n", dc_version(NULL)); } +void print_files() +{ + const char *branchp, *remote; + const char *filename, *local_git; + + filename = cloud_url(); + + is_git_repository(filename, &branchp, &remote, true); + local_git = get_local_dir(remote, branchp); + printf("\nFile locations (modify at your own risk):\n\n"); + printf("Local git storage: %s\n", local_git); + printf("Cloud URL: %s\n", cloud_url()); + printf("Image hashes: %s\n", hashfile_name_string()); + printf("Local picture directory: %s\n\n", picturedir_string()); +} + static void print_help() { print_version(); diff --git a/subsurfacestartup.h b/subsurfacestartup.h index 44db42e..8c70c1f 100644 --- a/subsurfacestartup.h +++ b/subsurfacestartup.h @@ -16,6 +16,7 @@ extern bool imported; void setup_system_prefs(void); void parse_argument(const char *arg); void free_prefs(void); +void print_files(void); #ifdef __cplusplus } -- 2.3.8 (Apple Git-58)