diff options
author | 2017-03-27 17:59:16 -0400 | |
---|---|---|
committer | 2017-03-27 17:59:16 -0400 | |
commit | bd69b39248d111044ef68e231df7ed3c70a32367 (patch) | |
tree | 3d8a2d096a49c6b279272e30fdca20f6c95ec8f0 | |
parent | disable tmpfs on ~/.cache (diff) | |
parent | create ~/.local/share/applications directory if it doesn't exist - fixing #1081 (diff) | |
download | firejail-bd69b39248d111044ef68e231df7ed3c70a32367.tar.gz firejail-bd69b39248d111044ef68e231df7ed3c70a32367.tar.zst firejail-bd69b39248d111044ef68e231df7ed3c70a32367.zip |
Merge pull request #1164 from startx2017/master
firecfg: create ~/.local/share/applications directory if it doesn't exist
-rw-r--r-- | src/firecfg/main.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c index 054df9e09..670b3d839 100644 --- a/src/firecfg/main.c +++ b/src/firecfg/main.c | |||
@@ -295,30 +295,45 @@ static void set(void) { | |||
295 | } | 295 | } |
296 | 296 | ||
297 | static void fix_desktop_files(void) { | 297 | static void fix_desktop_files(void) { |
298 | struct stat sb; | ||
299 | |||
300 | // check user | ||
298 | if (getuid() == 0) { | 301 | if (getuid() == 0) { |
299 | fprintf(stderr, "Error: you should run --fix as user\n"); | 302 | fprintf(stderr, "Error: this option is not supported for root user; please run as a regular user.\n"); |
300 | exit(1); | 303 | exit(1); |
301 | } | 304 | } |
302 | |||
303 | char *homedir = getenv("HOME"); | 305 | char *homedir = getenv("HOME"); |
304 | if (!homedir) | 306 | if (!homedir) |
305 | errExit("getenv"); | 307 | errExit("getenv"); |
306 | 308 | ||
309 | // destination | ||
310 | // create ~/.local/share/applications directory if necessary | ||
307 | char *user_apps_dir; | 311 | char *user_apps_dir; |
308 | if (asprintf(&user_apps_dir, "%s/.local/share/applications", homedir) == -1) | 312 | if (asprintf(&user_apps_dir, "%s/.local/share/applications", homedir) == -1) |
309 | errExit("asprintf"); | 313 | errExit("asprintf"); |
314 | if (stat(user_apps_dir, &sb) == -1) { | ||
315 | int rv = mkdir(user_apps_dir, 0700); | ||
316 | if (rv) { | ||
317 | fprintf(stderr, "Error: cannot create ~/.local/application directory\n"); | ||
318 | perror("mkdir"); | ||
319 | exit(1); | ||
320 | } | ||
321 | rv = chmod(user_apps_dir, 0700); | ||
322 | (void) rv; | ||
323 | } | ||
310 | 324 | ||
325 | // source | ||
311 | DIR *dir = opendir("/usr/share/applications"); | 326 | DIR *dir = opendir("/usr/share/applications"); |
312 | if (!dir) { | 327 | if (!dir) { |
313 | perror("Error: cannot open /usr/share/applications directory"); | 328 | perror("Error: cannot open /usr/share/applications directory"); |
314 | exit(1); | 329 | exit(1); |
315 | } | 330 | } |
316 | |||
317 | if (chdir("/usr/share/applications")) { | 331 | if (chdir("/usr/share/applications")) { |
318 | perror("Error: cannot chdir to /usr/share/applications"); | 332 | perror("Error: cannot chdir to /usr/share/applications"); |
319 | exit(1); | 333 | exit(1); |
320 | } | 334 | } |
321 | 335 | ||
336 | // copy | ||
322 | struct dirent *entry; | 337 | struct dirent *entry; |
323 | while ((entry = readdir(dir)) != NULL) { | 338 | while ((entry = readdir(dir)) != NULL) { |
324 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | 339 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) |
@@ -337,8 +352,6 @@ static void fix_desktop_files(void) { | |||
337 | // skip links | 352 | // skip links |
338 | if (is_link(filename)) | 353 | if (is_link(filename)) |
339 | continue; | 354 | continue; |
340 | |||
341 | struct stat sb; | ||
342 | if (stat(filename, &sb) == -1) | 355 | if (stat(filename, &sb) == -1) |
343 | errExit("stat"); | 356 | errExit("stat"); |
344 | 357 | ||