Add -p flag to disable writing of cache and temporary files

Closes #285.
This commit is contained in:
Antti Korpi 2017-07-13 01:15:51 +01:00 committed by Bert Münnich
parent 20009c240b
commit ecc363ec10
4 changed files with 16 additions and 4 deletions

View file

@ -32,7 +32,7 @@ const options_t *options = (const options_t*) &_options;
void print_usage(void) void print_usage(void)
{ {
printf("usage: sxiv [-abcfhioqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
"[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] " "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] "
"FILES...\n"); "FILES...\n");
} }
@ -72,8 +72,9 @@ void parse_options(int argc, char **argv)
_options.quiet = false; _options.quiet = false;
_options.thumb_mode = false; _options.thumb_mode = false;
_options.clean_cache = false; _options.clean_cache = false;
_options.private_mode = false;
while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) { while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) {
switch (opt) { switch (opt) {
case '?': case '?':
print_usage(); print_usage();
@ -129,6 +130,9 @@ void parse_options(int argc, char **argv)
case 'o': case 'o':
_options.to_stdout = true; _options.to_stdout = true;
break; break;
case 'p':
_options.private_mode = true;
break;
case 'q': case 'q':
_options.quiet = true; _options.quiet = true;
break; break;

View file

@ -50,6 +50,7 @@ typedef struct {
bool quiet; bool quiet;
bool thumb_mode; bool thumb_mode;
bool clean_cache; bool clean_cache;
bool private_mode;
} options_t; } options_t;
extern const options_t *options; extern const options_t *options;

5
sxiv.1
View file

@ -3,7 +3,7 @@
sxiv \- Simple X Image Viewer sxiv \- Simple X Image Viewer
.SH SYNOPSIS .SH SYNOPSIS
.B sxiv .B sxiv
.RB [ \-abcfhioqrtvZ ] .RB [ \-abcfhiopqrtvZ ]
.RB [ \-A .RB [ \-A
.IR FRAMERATE ] .IR FRAMERATE ]
.RB [ \-e .RB [ \-e
@ -80,6 +80,9 @@ with
.B \-i .B \-i
sxiv can be used as a visual filter/pipe. sxiv can be used as a visual filter/pipe.
.TP .TP
.B \-p
Enable private mode, in which sxiv does not write any cache or temporary files.
.TP
.B \-q .B \-q
Be quiet, disable warnings to standard error stream. Be quiet, disable warnings to standard error stream.
.TP .TP

View file

@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <utime.h> #include <utime.h>
#include "options.h"
#include "thumbs.h" #include "thumbs.h"
#include "util.h" #include "util.h"
@ -83,6 +84,9 @@ void tns_cache_write(Imlib_Image im, const char *filepath, bool force)
struct utimbuf times; struct utimbuf times;
Imlib_Load_Error err = 0; Imlib_Load_Error err = 0;
if (options->private_mode)
return;
if (stat(filepath, &fstats) < 0) if (stat(filepath, &fstats) < 0)
return; return;
@ -270,7 +274,7 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
cache_hit = true; cache_hit = true;
} }
#if HAVE_LIBEXIF #if HAVE_LIBEXIF
} else if (!force) { } else if (!force && !options->private_mode) {
int pw = 0, ph = 0, w, h, x = 0, y = 0; int pw = 0, ph = 0, w, h, x = 0, y = 0;
bool err; bool err;
float zw, zh; float zw, zh;