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

Detect an unusable Home directory #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions unoconv
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import getopt
import glob
import os
import signal
import shutil
import subprocess
import sys
import tempfile
import time

__version__ = '0.8.2'
Expand Down Expand Up @@ -717,6 +719,12 @@ class Options:

self.filenames = args

# Check usability of invoking user's home directory
# (`os.path.expanduser()` takes into account the `HOME` environment value, if set.)
if not os.access(os.path.expanduser('~'), os.R_OK | os.W_OK):
print('unoconv: Home directory not usable (read/write). Using a temporary folder.', file=sys.stderr)
os.environ['HOME'] = tempfile.mkdtemp(prefix='unoconv.')

if not self.listener and not self.showlist and not self.stdin and self.doctype != 'list' and not self.filenames:
print('unoconv: you have to provide a filename or url as argument', file=sys.stderr)
print('Try `unoconv -h\' for more information.', file=sys.stderr)
Expand Down Expand Up @@ -1332,6 +1340,10 @@ def die(ret, msg=None):
info(3, 'Waiting for %s with pid %s to disappear.' % (ooproc.pid, product.ooName))
ooproc.wait()

# Check for and remove temporary HOME
if 'HOME' in os.environ and os.path.basename(os.environ['HOME']).startswith('unoconv.'):
shutil.rmtree(os.environ['HOME'])

# Allow Python GC to garbage collect pyuno object *before* exit call
# which avoids random segmentation faults --vpa
convertor = None
Expand Down