Skip to content

Commit

Permalink
Don't set TARGETDIR in config by default but compute a sane default v…
Browse files Browse the repository at this point in the history
…alue

The default value is determined as follows:

- Use $TARGETDIR if set in the configuration file.
- Else use $XDG_RUNTIME_DIR/$UID if it exists.
- Else use /run/user/$UID if it exists.
- Else use $TMPDIR if it exists.
- Else use /tmp/.

Requires new runtime dependency libfile-slurp-perl.

For coverage computation, the test suite is run twice, once with and
once without $TMPDIR and $XDG_RUNTIME_DIR being set.

Closes: #780387
  • Loading branch information
xtaran committed Jul 4, 2015
1 parent 8f50e93 commit 65f632b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ test: pureperltest

determine-coverage:
cover -delete
prove --exec 'env PERL5OPT=-MDevel::Cover=-ignore_re,^t/ perl' t/*.t
prove --exec 'env -u TMPDIR -u XDG_RUNTIME_DIR PERL5OPT=-MDevel::Cover=-ignore_re,^t/ perl' t/*.t
prove --exec 'env TMPDIR=/foo XDG_RUNTIME_DIR=/bar PERL5OPT=-MDevel::Cover=-ignore_re,^t/ perl' t/*.t

cover: determine-coverage
cover -report html_basic
Expand Down
25 changes: 24 additions & 1 deletion bin/unburden-home-dir
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,39 @@ use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1;
use File::Path qw(mkpath rmtree);
use File::Basename;
use File::BaseDir qw(config_home);
use File::Slurp;
use File::Touch;
use File::Rsync;
use File::Which;
use IO::Handle;
use String::Expand;
use Data::Dumper;

# Determine default value for target directory
my $default_target = '/tmp';
if (defined($ENV{TMPDIR})) { # defined() doesn't autovivicate
$default_target = $ENV{TMPDIR};
}
if (-r '/proc/mounts') {
my $runtime_dir = '/run/user';
if (defined($ENV{XDG_RUNTIME_DIR})) { # defined() doesn't autovivicate
$runtime_dir = $ENV{XDG_RUNTIME_DIR};
}
$runtime_dir .= "/$<"; # typically something like /run/user/1000

my @mounts = read_file('/proc/mounts');
foreach my $mount (@mounts) {
my @mount = split(/\s+/, $mount);
if ($mount[1] eq $runtime_dir) {
$default_target = $runtime_dir;
last;
}
}
}

# Configuration variables to be used in configuration files
my $CONFIG = {
TARGETDIR => '/tmp',
TARGETDIR => $default_target,
FILELAYOUT => '.unburden-%u/%s',
};

Expand Down
10 changes: 10 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ unburden-home-dir (0.4~dev) UNRELEASED; urgency=medium
* Use "gzip -n" to make sure the build stays reproducible.
* Skip tests which involve the non-readabliity of files if run as
root. (Closes: #789832)
* Don't set TARGETDIR in configuration file by default but compute a
sane default value inside unburden-home-dir (Closes: #780387):
- Use $TARGETDIR if set in the configuration file.
- Else use $XDG_RUNTIME_DIR/$UID if it exists.
- Else use /run/user/$UID if it exists.
- Else use $TMPDIR if it exists.
- Else use /tmp/.
+ Requires new runtime dependency libfile-slurp-perl.
+ Run test suite multiple times with different environments for
coverage computation.

-- Axel Beckert <abe@debian.org> Fri, 13 Mar 2015 13:11:26 +0100

Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Architecture: all
Depends: libconfig-file-perl,
libfile-basedir-perl,
libfile-rsync-perl,
libfile-slurp-perl,
libfile-touch-perl,
libfile-which-perl,
libstring-expand-perl,
Expand Down
4 changes: 0 additions & 4 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ Features
in `unburden-home-dir.list` for alternative locations of `.cache`
and friends.

* Use `/run/user/$USERID` aka `$XDG_RUNTIME_DIR` as target if
present. See also
[Debian Bug-Report #780387](https://bugs.debian.org/780387).

These features likely all will need expansion of environment
variables in configuration files or values.

Expand Down
2 changes: 1 addition & 1 deletion etc/unburden-home-dir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#
# Parsed by Config::File

TARGETDIR=/tmp
#TARGETDIR=/tmp
FILELAYOUT='.unburden-%u/%s'
#DEBUG=

0 comments on commit 65f632b

Please sign in to comment.