]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the log/ini owner for VentoyGUI in linux.
authorlongpanda <admin@ventoy.net>
Fri, 8 Apr 2022 07:35:22 +0000 (15:35 +0800)
committerlongpanda <admin@ventoy.net>
Fri, 8 Apr 2022 07:35:22 +0000 (15:35 +0800)
INSTALL/VentoyGUI.aarch64
INSTALL/VentoyGUI.i386
INSTALL/VentoyGUI.mips64el
INSTALL/VentoyGUI.x86_64
LinuxGUI/Ventoy2Disk/ventoy_gui.c

index 6b1f5dcdfccdb12a7428ea5479e449b12658eebb..35d51b31a95b4c9e664e98631a3b51e7734d02fa 100644 (file)
Binary files a/INSTALL/VentoyGUI.aarch64 and b/INSTALL/VentoyGUI.aarch64 differ
index 0824dd49de88a51665aee0386bc7f43bebe9500f..b073fb95b3a110093d422ef61315ba21da7e933b 100644 (file)
Binary files a/INSTALL/VentoyGUI.i386 and b/INSTALL/VentoyGUI.i386 differ
index 46e882874c1052ce62c6908ecaf4ffd69b483206..d30bea7e47c39d9965fc2aae84628f1349ccc76a 100644 (file)
Binary files a/INSTALL/VentoyGUI.mips64el and b/INSTALL/VentoyGUI.mips64el differ
index 71b6b4bdabd0323e15b0f6173eab0eaf567da699..1e208fa83364bd37cb364c23379cb7e33a02ec94 100644 (file)
Binary files a/INSTALL/VentoyGUI.x86_64 and b/INSTALL/VentoyGUI.x86_64 differ
index 2616f5e0a9d9c5c3d406b23f8dd18985b60553d0..45bae96956940b58638870bb3fb76ed0b9edc1a7 100644 (file)
@@ -303,6 +303,58 @@ static int read_pid_cmdline(long pid, char *Buffer, int BufLen)
     return read_file_1st_line(path, Buffer, BufLen);
 }
 
+static int is_dir_exist(const char *fmt, ...)
+{
+    va_list arg;
+    struct stat st;
+    char path[4096];
+
+    va_start(arg, fmt);
+    vsnprintf(path, sizeof(path), fmt, arg);
+    va_end(arg);
+
+    memset(&st, 0, sizeof(st));
+    if (stat(path, &st) < 0)
+    {
+        return 0;
+    }
+
+    if (st.st_mode & S_IFDIR)
+    {
+        return 1;
+    }
+
+    return 0;
+}
+
+static void touch_new_file(char *filename)
+{
+    char *pos = NULL;
+    FILE *fp = NULL;
+
+    if (access(filename, F_OK) == -1)
+    {
+        for (pos = filename; *pos; pos++)
+        {
+            if (*pos == '/')
+            {
+                *pos = 0;
+                if (!is_dir_exist("%s", filename))
+                {
+                    mkdir(filename, 0755);
+                }
+                *pos = '/';
+            }
+        }
+    
+        fp = fopen(filename, "w+");
+        if (fp)
+        {
+            fclose(fp);
+        }        
+    }    
+}
+
 static int find_exe_path(const char *exe, char *pathbuf, int buflen)
 {
     int i;
@@ -1250,8 +1302,12 @@ int main(int argc, char **argv)
     {
         if (argv[i] && argv[i + 1] && strcmp(argv[i], "-l") == 0)
         {
+            touch_new_file(argv[i + 1]);
             snprintf(g_log_file, sizeof(g_log_file), "%s", argv[i + 1]);
-            break;
+        }
+        else if (argv[i] && argv[i + 1] && strcmp(argv[i], "-i") == 0)
+        {
+            touch_new_file(argv[i + 1]);
         }
         else if (argv[i] && strcmp(argv[i], "--xdg") == 0)
         {
@@ -1260,6 +1316,7 @@ int main(int argc, char **argv)
             {
                 g_xdg_log = 1;
                 snprintf(g_log_file, sizeof(g_log_file), "%s/ventoy.log", env);
+                touch_new_file(g_log_file);
             }
             
             env = getenv("XDG_CONFIG_HOME");
@@ -1267,6 +1324,7 @@ int main(int argc, char **argv)
             {
                 g_xdg_ini = 1;
                 snprintf(g_ini_file, sizeof(g_ini_file), "%s/Ventoy2Disk.ini", env);
+                touch_new_file(g_ini_file);
             }
         }
     }