Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When $TMPDIR is /tmp/foo, leptonica's magic turns /tmp/bar into /tmp/foo/foo/bar. #224

Closed
TaylanUB opened this issue Dec 19, 2016 · 10 comments

Comments

@TaylanUB
Copy link

Leptonica's test suite passes fine normally, but all tests fail with dozens of "stream not opened" and similar file-related errors when I build Leptonica 1.73 via GNU Guix (which has a peculiar build environment).

Within the Guix build environment, TMPDIR is set to /tmp/builddir. By using strace I noticed that the regression test programs try to open or create files like /tmp/builddir/builddir/foo which fails because the directory /tmp/builddir/builddir doesn't exist.

Sniffing around Leptonica's source code I found out about the genPathname function which contains magic that turns any filename like /tmp/... into $TMPDIR/.... I suspect that some functions effectively pass a given filename through genPathname twice, so that when TMPDIR is /tmp/foo, a filename like /tmp/blahblah becomes /tmp/foo/blahblah on the first pass, and /tmp/foo/foo/blahblah on the second pass. (Because the /tmp part of /tmp/foo/blah is also turned into /tmp/foo during the second pass.)

I'm sorry that I don't have more precise information right now, like how filenames end up being passed through that transformation two times. I'll take a better look when I find time, if nobody does it on the meanwhile.

@TaylanUB
Copy link
Author

Steps to reproduce:

  • mkdir /tmp/leptonica-test
  • export TMPDIR=/tmp/leptonica-test
  • cd $leptonica_source_directory
  • ./configure && make && make check

@DanBloomberg
Copy link
Owner

I believe this problem is now fixed. Download from the head of this tree and see if the tests now work properly with your TMPDIR.

-- Dan

@TaylanUB
Copy link
Author

TaylanUB commented Dec 20, 2016

Unfortunately it seems I can still reproduce the issue on the head of the master branch.

@DanBloomberg
Copy link
Owner

Investigating ...

@DanBloomberg
Copy link
Owner

There are multiple issues. I expect to have the fixes in by tomorrow.

@DanBloomberg
Copy link
Owner

Should work OK now. Please give it another try from head.

@TaylanUB
Copy link
Author

Thank you! This solves the issue. :-)

Unfortunately (but not surprisingly) the patch can't be applied on top of 1.73. I'm trying to figure out workarounds to make Guix's Leptonica 1.73 package work. Please tell if you have any good ideas. Otherwise, feel free to close the issue.

@DanBloomberg
Copy link
Owner

Far too much has changed for that patch to work on 1.73.
Glad we could put this issue to rest.

-- Dan

@vuori777
Copy link

vuori777 commented Apr 1, 2017

Is the fix applied to 1.74.1? I'm seeing a spurious "file not found" in fopenReadStream when TMPDIR is set after updating from 1.69.

@DanBloomberg
Copy link
Owner

Yes. The fixes were made on 12/21/16 and 1.74.1 was released on 1/4/17.

Here is the checkin message:
Fix problems when $TMPDIR exists on unix and is /tmp/

  • Use: export TMPDIR=/tmp/builddir (to test)
  • in gplot.c: pathnames in the command file are the actual pathnames,
    and must not be rewritten. In gplotCreate(), use the canonical (not
    rewritten) name in gplot->cmdname, and in gplotMakeOutput(), use
    genPathname() on the command file name so that gnuplot can find it.
  • in utils2.c, do not rewrite the paths for unix in:
    makeTempDirname(), lept_mv(), lept_cp()
    except where the library or system call cannot do the translation.
  • in utils2.c, in pathJoin(), allow paths to start with '.', but not '..'
  • in utils2.c and everywhere that l_makeTempfile() is used,
    remove subdir arg (nobody is using it)
  • in sarray1.c: use pathJoin() instead of genPathname() in
    getSortedPathnamesInDirectory().
  • in bmf.c and prog/genfonts_reg.c, replace all genPathname() by pathJoin().
  • in regutils.c: in regTestSetup() and regTestCleanup(), replace
    genPathname() by stringNew()
  • in writefile.c: in pixWrite(), remove call to genPathname(). Also
    replace genPathname() by pathJoin() in deprecated pixDisplayWriteFormat().
  • in morphseq.c: remove calls to genPathname in all the pixMorphSequence()
  • in dewarp4.c: remove genPathname() calls
  • in files_reg.c: various changes required to lept_mv(), lept_cp(), lept_rm()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants