diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-08-29 17:16:43 +0200 |
---|---|---|
committer | Linn Mattsson <linma@cendio.se> | 2024-10-22 12:41:33 +0200 |
commit | c5fc94af7b07bfad0263f407b85906dc38c8ef5b (patch) | |
tree | cd1bbd4a3a9b2ca5851d46a31662b4ad0b7d06e2 | |
parent | fdbc92f8cc59e5ae59949d68319c8a61e270b701 (diff) | |
download | tigervnc-c5fc94af7b07bfad0263f407b85906dc38c8ef5b.tar.gz tigervnc-c5fc94af7b07bfad0263f407b85906dc38c8ef5b.zip |
Move base directory creation to helper function
This is non-trivial now, so let's modularize this a bit.
(cherry picked from commit 0c61c069bab38d14b93ad9d71b6509427a5611a8)
-rw-r--r-- | vncviewer/vncviewer.cxx | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 366327fa..d9f85f5a 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -528,6 +528,36 @@ migrateDeprecatedOptions() } } +static void +create_base_dirs() +{ + char *confdir = strdup(os::getvncconfigdir()); +#ifndef WIN32 + char *dotdir = strrchr(confdir, '.'); + if (dotdir != NULL && strcmp(dotdir, ".vnc") == 0) + vlog.info(_("~/.vnc is deprecated, please consult 'man vncviewer' for paths to migrate to.")); +#else + char *vncdir = strrchr(confdir, '\\'); + if (vncdir != NULL && strcmp(vncdir, "vnc") == 0) + vlog.info(_("%%APPDATA%%\\vnc is deprecated, please switch to the %%APPDATA%%\\TigerVNC location.")); +#endif + + if (os::mkdir_p(os::getvncconfigdir(), 0755) == -1) { + if (errno != EEXIST) + vlog.error(_("Could not create VNC config directory: %s"), strerror(errno)); + } + + if (os::mkdir_p(os::getvncdatadir(), 0755) == -1) { + if (errno != EEXIST) + vlog.error(_("Could not create VNC data directory: %s"), strerror(errno)); + } + + if (os::mkdir_p(os::getvncstatedir(), 0755) == -1) { + if (errno != EEXIST) + vlog.error(_("Could not create VNC state directory: %s"), strerror(errno)); + } +} + #ifndef WIN32 static int interpretViaParam(char *remoteHost, int *remotePort, int localPort) @@ -714,31 +744,7 @@ int main(int argc, char** argv) migrateDeprecatedOptions(); - char *confdir = strdup(os::getvncconfigdir()); -#ifndef WIN32 - char *dotdir = strrchr(confdir, '.'); - if (dotdir != NULL && strcmp(dotdir, ".vnc") == 0) - vlog.info(_("~/.vnc is deprecated, please consult 'man vncviewer' for paths to migrate to.")); -#else - char *vncdir = strrchr(confdir, '\\'); - if (vncdir != NULL && strcmp(vncdir, "vnc") == 0) - vlog.info(_("%%APPDATA%%\\vnc is deprecated, please switch to the %%APPDATA%%\\TigerVNC location.")); -#endif - - if (os::mkdir_p(os::getvncconfigdir(), 0755) == -1) { - if (errno != EEXIST) - vlog.error(_("Could not create VNC config directory: %s"), strerror(errno)); - } - - if (os::mkdir_p(os::getvncdatadir(), 0755) == -1) { - if (errno != EEXIST) - vlog.error(_("Could not create VNC data directory: %s"), strerror(errno)); - } - - if (os::mkdir_p(os::getvncstatedir(), 0755) == -1) { - if (errno != EEXIST) - vlog.error(_("Could not create VNC state directory: %s"), strerror(errno)); - } + create_base_dirs(); CSecurity::upg = &dlg; #if defined(HAVE_GNUTLS) || defined(HAVE_NETTLE) |