about summary refs log tree commit diff stats
path: root/src/command/cmd_funcs.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-02-24 11:57:25 +0100
committerMichael Vetter <jubalh@iodoru.org>2022-02-24 11:57:25 +0100
commit6d17b36605292a0eda148178677f72819c80b6fe (patch)
treecdc0e9c6cb81b2592ded9c1e470d1d88fe667cf5 /src/command/cmd_funcs.c
parent8173878bc7ce5b502a967186f847c8f7cf33ed72 (diff)
downloadprofani-tty-6d17b36605292a0eda148178677f72819c80b6fe.tar.gz
ox: expand file and check for existance before trying to announce
Output before:
```
11:00:00 - Annonuce OpenPGP Key for OX ~/test/testuser.pub.gpg ...
```

After:
```
11:00:00 - Annonuce OpenPGP Key for OX /home/user/test/testuser.pub.gpg ...
```

Now we expand the path so that we can check for `~` properly.
And test if the file is actually a normal file.
Diffstat (limited to 'src/command/cmd_funcs.c')
-rw-r--r--src/command/cmd_funcs.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 4b79b145..0219b61f 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -7613,7 +7613,22 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
         return TRUE;
     } else if (g_strcmp0(args[0], "announce") == 0) {
         if (args[1]) {
-            ox_announce_public_key(args[1]);
+            gchar* filename = get_expanded_path(args[1]);
+
+            if (access(filename, R_OK) != 0) {
+                cons_show_error("File not found: %s", filename);
+                g_free(filename);
+                return TRUE;
+            }
+
+            if (!is_regular_file(filename)) {
+                cons_show_error("Not a file: %s", filename);
+                g_free(filename);
+                return TRUE;
+            }
+
+            ox_announce_public_key(filename);
+            free(filename);
         } else {
             cons_show("Filename is required");
         }