On Thu, Mar 20, 2014 at 06:08:58PM +0100, Sebastian Ramacher wrote:
> On 2014-03-20 17:12:41, Hans Ekbrand wrote:
> > > > 2. It causes confusing messages on stderr, which in turn can mess up
> > > >    the screen state of the calling program.
> > > 
> > > Which one?
> 
> I meant the "confusing messages on stderr". What's the error message?

info: successfully loaded plugin /usr/lib/zathura/pdf.so
info: Using plain database backend.

> So, to be clear what I meant: consider a document named /a/b.pdf. If one
> opens the file from within zathura or by passing it as argument to
> zathura, bookmarks and all the other stored information will be
> available.  However, with that menu entry, opening from mc will not
> preserve that.  And this is not solved by using a deterministic name in
> /tmp.
> 
> But the addition of a using deterministic name in /tmp also breaks other
> use cases. Assume user A opens /a/c.pdf and user B opens /b/c.pdf (both
> do this via mc), which file do they see?

You're right, copying the file is not the solution here. run-mailcap
already provides a nice mechanism, put a randomly named symlink in
/tmp which points back to the real file, give the viewer program
(zathura, in our case) the symlink. This mechanism is used whenever
the filename contains character(s) that the shell needs to be
protected from. While the mechanism is nice, it is not used in all
cases which introduces a complexity that has to be dealt with.

So, then, in what I think would solve the problem without reducing the
features of zathura, I propose this entry:

application/pdf; { TEMPSYMLINK=`mktemp` \; rm $TEMPSYMLINK  \; if test -L '%s' 
\; then cp -a '%s' $TEMPSYMLINK \; else CURRDIR=`pwd` \; FILE=`dir '%s'` \; ln 
-s "${CURRDIR}/${FILE}" $TEMPSYMLINK \; fi \; ( zathura $TEMPSYMLINK >/dev/null 
2>&1 \; rm $TEMPSYMLINK ) & } ; test=test -n "$DISPLAY"; description=Portable 
Document Format; nametemplate=%s.pdf; 
application/pdf; { TEMPSYMLINK=`mktemp` \; rm $TEMPSYMLINK  \; if test -L '%s' 
\; then cp -a '%s' $TEMPSYMLINK \; else CURRDIR=`pwd` \; FILE=`dir '%s'` \; ln 
-s "${CURRDIR}/${FILE}" $TEMPSYMLINK \; fi \; ( zathura $TEMPSYMLINK >/dev/null 
2>&1 \; rm $TEMPSYMLINK ) & } ; test=test -n "$DISPLAY"; description=Portable 
Document Format; nametemplate=%s.pdf; 
application/x-pdf; { TMP=`basename '%s'` \; cp -a '%s' "/tmp/$TMP.tmp" \; 
(zathura --fork "/tmp/$TMP.tmp" >/dev/null 2>&1 && sleep 5 && rm 
"/tmp/$TMP.tmp" & ) } ; test=test -n "$DISPLAY"; description=Portable Document 
Format; nametemplate=%s.pdf; 

In order to see what it does, here is the code commented line by line

## Get a random name
TEMPSYMLINK=`mktemp` \;
## Remove that file, we only wanted the name
rm $TEMPSYMLINK  \;
## Test if '%s' is a symlink or not
if test -L '%s' \; then
    ## '%s' is a symlink, we copy this one with "cp -a" to our own TEMPSYMLINK
    cp -a '%s' $TEMPSYMLINK \;
else
    ## '%s' is not a symlink, locate it
    CURRDIR=`pwd` \;
    FILE=`dir '%s'` \;
    ## make a symlink from our TEMPSYMLINK to wherever '%s' is
    ln -s "${CURRDIR}/${FILE}" $TEMPSYMLINK \;
fi \;
## fork by starting zathura in sub shell,
## remove our TEMPSYMLINK when zathura exits
 ( zathura $TEMPSYMLINK >/dev/null 2>&1 \; rm $TEMPSYMLINK ) &

Now, some testing

1. file without protected characters in the name, in $HOME

$ see --debug foo.pdf
 - parsing parameter "foo.pdf"
 - Reading mime.types file "/etc/mime.types"...
 - extension "pdf" maps to mime-type "application/pdf"
 - Reading mailcap file "/home/hans/.mailcap"...
 - Reading mailcap file "/etc/mailcap"...
Processing file "foo.pdf" of type "application/pdf" (encoding=none)...
 - checking mailcap entry "application/pdf; { TEMPSYMLINK=`mktemp`  rm 
$TEMPSYMLINK   if test -L '%s'  then cp -a '%s' $TEMPSYMLINK  else 
CURRDIR=`pwd`  FILE=`dir '%s'`  ln -s "${CURRDIR}/${FILE}" $TEMPSYMLINK  fi  ( 
zathura $TEMPSYMLINK >/dev/null 2>&1  rm $TEMPSYMLINK ) & } ; test=test -n 
"$DISPLAY"; description=Portable Document Format; nametemplate=%s.pdf; "
 - program to execute: { TEMPSYMLINK=`mktemp`  rm $TEMPSYMLINK   if test -L 
'%s'  then cp -a '%s' $TEMPSYMLINK  else CURRDIR=`pwd`  FILE=`dir '%s'`  ln -s 
"${CURRDIR}/${FILE}" $TEMPSYMLINK  fi  ( zathura $TEMPSYMLINK >/dev/null 2>&1  
rm $TEMPSYMLINK ) & }
 - running test: test -n "$DISPLAY"  (result=0=true)
 - executing: { TEMPSYMLINK=`mktemp` ; rm $TEMPSYMLINK  ; if test -L 'foo.pdf' 
; then cp -a 'foo.pdf' $TEMPSYMLINK ; else CURRDIR=`pwd` ; FILE=`dir 'foo.pdf'` 
; ln -s "${CURRDIR}/${FILE}" $TEMPSYMLINK ; fi ; ( zathura $TEMPSYMLINK 
>/dev/null 2>&1 ; rm $TEMPSYMLINK ) & }

zathura is started and the file is opened. In /tmp the following has happened:

ls -lStr /tmp/ | tail -n 1
lrwxrwxrwx 1 hans hans   18 mar 20 20:39 tmp.zxMFFkjgeb -> /home/hans/foo.pdf

After closing zathura, this symlink is removed:

ls -lStr /tmp/tmp.zxMFFkjgeb
ls: cannot access /tmp/tmp.zxMFFkjgeb: No such file or directory

2. file with protected characters in the name, in a subdir with a space in its 
name

$ see --debug test\ mailcap/5\!\&.pdf
 - parsing parameter "test mailcap/5!&.pdf"
 - Reading mime.types file "/etc/mime.types"...
 - extension "pdf" maps to mime-type "application/pdf"
 - Reading mailcap file "/home/hans/.mailcap"...
 - Reading mailcap file "/etc/mailcap"...
Processing file "test mailcap/5!&.pdf" of type "application/pdf" 
(encoding=none)...
 - checking mailcap entry "application/pdf; { TEMPSYMLINK=`mktemp`   rm 
$TEMPSYMLINK    if test -L '%s'   then cp -a '%s' $TEMPSYMLINK   else 
CURRDIR=`pwd`   FILE=`dir '%s'`   ln -s "${CURRDIR}/${FILE}" $TEMPSYMLINK   fi  
 ( zathura $TEMPSYMLINK >/dev/null 2>&1   rm $TEMPSYMLINK ) & } ; test=test -n 
"$DISPLAY"; description=Portable Document Format; nametemplate=%s.pdf; "
 - program to execute: { TEMPSYMLINK=`mktemp`   rm $TEMPSYMLINK    if test -L 
'%s'   then cp -a '%s' $TEMPSYMLINK   else CURRDIR=`pwd`   FILE=`dir '%s'`   ln 
-s "${CURRDIR}/${FILE}" $TEMPSYMLINK   fi   ( zathura $TEMPSYMLINK >/dev/null 
2>&1   rm $TEMPSYMLINK ) & }
 - running test: test -n "$DISPLAY"  (result=0=true)
 - filename contains shell meta-characters; aliased to '/tmp/fileJ4aSwy.pdf'
 - executing: { TEMPSYMLINK=`mktemp` ; rm $TEMPSYMLINK  ; if test -L 
'/tmp/fileJ4aSwy.pdf' ; then cp -a '/tmp/fileJ4aSwy.pdf' $TEMPSYMLINK ; else 
CURRDIR=`pwd` ; FILE=`dir '/tmp/fileJ4aSwy.pdf'` ; ln -s "${CURRDIR}/${FILE}" 
$TEMPSYMLINK ; fi ; ( zathura $TEMPSYMLINK >/dev/null 2>&1 ; rm $TEMPSYMLINK ) 
& }

In /tmp we have

ls -lStr /tmp/ | tail -n 1
lrwxrwxrwx 1 hans hans   31 Mar 20 20:46 tmp.dH1bmlQJmv -> /home/hans/test 
mailcap/5!&.pdf

In both case 1 and case 2, zathura correctly remembered bookmarks.


-- 
Note that I use Debian version 7.4
Linux hans 3.2.0-4-686-pae #1 SMP Debian 3.2.54-2 i686 GNU/Linux


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to