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

change unpack dir under windows #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 8 additions & 18 deletions myldr/mktmpdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ char *par_mktmpdir ( char **argv ) {
/* NOTE: all arrays below are NULL terminated */
const char *temp_dirs[] = {
P_tmpdir,
".", NULL };
const char *temp_keys[] = { "PAR_TMPDIR",
#ifdef WIN32
"C:\\TEMP",
"LOCALAPPDATA",
#endif
".", NULL };
const char *temp_keys[] = { "PAR_TMPDIR", "TMPDIR", "TEMPDIR",
"TMPDIR", "TEMPDIR",
"TEMP", "TMP", NULL };
const char *user_keys[] = { "USER", "USERNAME", NULL };

Expand Down Expand Up @@ -138,19 +139,6 @@ char *par_mktmpdir ( char **argv ) {
}
}

#ifdef WIN32
/* Try the windows temp directory */
if ( tmpdir == NULL && (val = par_getenv("WinDir")) && strlen(val) ) {
char* buf = malloc(strlen(val) + 5 + 1);
sprintf(buf, "%s\\temp", val);
if (isWritableDir(buf)) {
tmpdir = buf;
} else {
free(buf);
}
}
#endif

/* Try default locations */
for ( i = 0 ; tmpdir == NULL && (val = temp_dirs[i]) && strlen(val) ; i++ ) {
if ( isWritableDir(val) ) {
Expand All @@ -166,14 +154,16 @@ char *par_mktmpdir ( char **argv ) {
strlen(subdirbuf_suffix) + 1024;

/* stmpdir is what we are going to return;
top_tmpdir is the top $TEMP/par-$USER, needed to build stmpdir.
top_tmpdir is the top $TEMP/par-$USER ($TEMP/pp on Windows),
needed to build stmpdir.
NOTE: We need 2 buffers because snprintf() can't write to a buffer
it is also reading from. */
top_tmpdir = malloc( stmp_len );
sprintf(top_tmpdir, "%s%s%s%s", tmpdir, dir_sep, subdirbuf_prefix, username);
#ifdef WIN32
sprintf(top_tmpdir, "%s\\pp", tmpdir);
_mkdir(top_tmpdir); /* FIXME bail if error (other than EEXIST) */
#else
sprintf(top_tmpdir, "%s%s%s%s", tmpdir, dir_sep, subdirbuf_prefix, username);
{
if (mkdir(top_tmpdir, 0700) == -1 && errno != EEXIST) {
fprintf(stderr, "%s: creation of private subdirectory %s failed (errno=%i)\n",
Expand Down
35 changes: 22 additions & 13 deletions script/par.pl
Original file line number Diff line number Diff line change
Expand Up @@ -750,28 +750,37 @@ sub _set_par_temp {
return;
}

# non-windows should not have LOCALAPPDATA, but just to be sure...
my @paths = $^O eq 'MSWin32'
? qw( PAR_TMPDIR LOCALAPPDATA TMPDIR TEMPDIR TEMP TMP )
: qw( PAR_TMPDIR TMPDIR TEMPDIR TEMP TMP );

foreach my $path (
(map $ENV{$_}, qw( PAR_TMPDIR TMPDIR TEMPDIR TEMP TMP )),
qw( C:\\TEMP /tmp . )
(map $ENV{$_}, @paths),
qw( /tmp . )
) {
next unless defined $path and -d $path and -w $path;
my $username;
my $pwuid;
# does not work everywhere:
eval {($pwuid) = getpwuid($>) if defined $>;};

if ( defined(&Win32::LoginName) ) {
$username = &Win32::LoginName;
}
elsif (defined $pwuid) {
$username = $pwuid;
# match code in mktempdir.c
my $stmpdir;
if ( $^O eq 'MSWin32' ) {
$stmpdir = "$path$Config{_delim}pp"
}
else {
$username = $ENV{USERNAME} || $ENV{USER} || 'SYSTEM';
my $pwuid;
# does not work everywhere:
eval {($pwuid) = getpwuid($>) if defined $>;};
if (defined $pwuid) {
$username = $pwuid;
}
else {
$username = $ENV{USERNAME} || $ENV{USER} || 'SYSTEM';
}
$username =~ s/\W/_/g;
$stmpdir = "$path$Config{_delim}par-".unpack("H*", $username);
}
$username =~ s/\W/_/g;

my $stmpdir = "$path$Config{_delim}par-".unpack("H*", $username);
mkdir $stmpdir, 0755;
if (!$ENV{PAR_CLEAN} and my $mtime = (stat($progname))[9]) {
open (my $fh, "<". $progname);
Expand Down