tmpfiles to $TMPDIR + better portability (mktemp)
mktemp: consider both FreeBSD/OSX and Linux OS having incompatible syntax From now on temporary files are saved in the folder specified by the environment variable $TMPDIR
This commit is contained in:
+15
-6
@@ -205,13 +205,22 @@ fi
|
||||
|
||||
|
||||
|
||||
# Initialize path to temporary files
|
||||
today=$(date +"%Y%m%d_%H%M")
|
||||
fld=$(basename "$FILE_INPUT_PDF" | sed 's/[.][^.]*$//')
|
||||
prefix="${today}.filename.${fld}"
|
||||
TMP_FLD=`TMPDIR=${TMP} mktemp -d -t "${prefix}XXXXXXXX"`
|
||||
# Initialize path to temporary files using mktemp
|
||||
|
||||
# Goal: save tmp file in a sub-folder of the $TMPDIR environment variable (or in "/tmp" if unset)
|
||||
# Unfortunately, Linux mktemp is not compatible with FreeBSD/OSX mktemp
|
||||
# Linux version requires no arg
|
||||
# FreeBSD requires '-t prefix' to be used so that $TMPDIR is taken into account
|
||||
# But in Linux '-t template' is handled differently than in FreeBSD
|
||||
# Therefore different calls must be used for Linux and for FreeBSD
|
||||
prefix="$(date +"%Y%m%d_%H%M").filename.$(basename "$FILE_INPUT_PDF" | sed 's/[.][^.]*$//')" # prefix made of date, time and pdf file name without extension
|
||||
TMP_FLD=`mktemp -d 2>/dev/null || mktemp -d -t "${prefix}" 2>/dev/null` # try Linux syntax first, if it fails try FreeBSD/OSX
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Could not create folder for temporary files. Please ensure you have sufficient right and \"$TMP\" exists"
|
||||
if [ -z "$TMPDIR" ]; then
|
||||
echo "Could not create folder for temporary files. Please ensure you have sufficient right and \"/tmp\" exists"
|
||||
else
|
||||
echo "Could not create folder for temporary files. Please ensure you have sufficient right and \"$TMPDIR\" exists"
|
||||
fi
|
||||
exit $EXIT_FILE_ACCESS_ERROR
|
||||
fi
|
||||
FILE_TMP="${TMP_FLD}/tmp.txt" # temporary file with a very short lifetime (may be used for several things)
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
DEFAULT_DPI=300 # dpi value used as fall back if the page dpi cannot be determined
|
||||
|
||||
TMP="./tmp" # location of the temporary files (one sub-folder will be created per PDF file to be processed)
|
||||
# an absolute path or a path relative to the OCRmyPDF installation should be entered
|
||||
|
||||
#####################################################################################
|
||||
# Do NOT change the following parameters
|
||||
#####################################################################################
|
||||
|
||||
Reference in New Issue
Block a user