Jeff Sheinberg jeff@bsrd.net
Jens Elkner elkner@imsgroup.de
Jens Schmidt jms@jsds.hamburg.com
+Jeph Cowan jeph@ucar.edu
Jeremy Maitin-Shepard jbms@cmu.edu
Jerome Abela abela@hsc.fr
Jérôme Zago bug-coreutils-ml@agt-the-walker.net
quote (template));
}
- dest_name = file_name_concat (dest_dir, template, NULL);
+ template = file_name_concat (dest_dir, template, NULL);
}
else
{
- dest_name = xstrdup (template);
+ template = xstrdup (template);
}
+ /* Make a copy to be used in case of diagnostic, since failing
+ mkstemp may leave the buffer in an undefined state. */
+ dest_name = xstrdup (template);
+
if (create_directory)
{
int err = mkdtemp_len (dest_name, x_count, dry_run);
if (err != 0)
{
error (0, errno, _("failed to create directory via template %s"),
- quote (dest_name));
+ quote (template));
status = EXIT_FAILURE;
}
}
if (fd < 0 || (!dry_run && close (fd) != 0))
{
error (0, errno, _("failed to create file via template %s"),
- quote (dest_name));
+ quote (template));
status = EXIT_FAILURE;
}
}
errno = saved_errno;
if (fd < 0)
- die (_("cannot create temporary file"), file);
+ error (SORT_FAILURE, errno, _("cannot create temporary file in %s"),
+ quote (temp_dir));
*pfd = fd;
return node;
fd = mkstemp (template);
if (fd < 0)
{
- error (0, errno, _("cannot create temporary file %s"), quote (tempfile));
+ error (0, errno, _("cannot create temporary file in %s"),
+ quote (tempdir));
return false;
}
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
my $prog = 'mktemp';
+my $bad_dir = 'no/such/dir';
my @Tests =
(
{POST => sub { my ($f) = @_; defined $f or return; chomp $f;
check_tmp $f, 'F'; unlink $f; rmdir 'a' or die "rmdir a: $!\n" }}
],
+
+ ['pipe-bad-tmpdir',
+ {ENV => "TMPDIR=$bad_dir"},
+ {ERR_SUBST => "s,($bad_dir/)[^']+': .*,\$1...,"},
+ {ERR => "$prog: failed to create file via template `$bad_dir/...\n"},
+ {EXIT => 1}],
);
my $save_temps = $ENV{DEBUG};
# this should fail since nmerge < # of input files, so
# temp files are needed
['nmerge-no', "-m --batch-size=2 -T$badtmp", @inputs,
- {ERR_SUBST=>"s|: $badtmp/sort.+||"},
- {ERR=>"$prog: cannot create temporary file\n"}, {EXIT=>2}],
+ {ERR_SUBST=>"s|': .*|':|"},
+ {ERR=>"$prog: cannot create temporary file in `$badtmp':\n"},
+ {EXIT=>2}],
# This used to fail because setting batch-size without also setting
# buffer size would cause the buffer size to be set to the minimum.
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
+my $bad_dir = 'no/such/dir';
+
my @Tests =
(
['segfault', '-r', {IN=>"a\n"}, {IN=>"b\n"}, {OUT=>"a\nb\n"}],
['opt-br2', qw(-b -r -s '\._+'),
{IN=>".__x.___y.____z._1._2.__3.___4"},
{OUT=>".___4.__3._2._1.____z.___y.__x"}],
+
+ ['pipe-bad-tmpdir',
+ {ENV => "TMPDIR=$bad_dir"},
+ {IN_PIPE => "a\n"},
+ {ERR_SUBST => "s,`$bad_dir': .*,...,"},
+ {ERR => "$prog: cannot create temporary file in ...\n"},
+ {EXIT => 1}],
);
@Tests = triple_test \@Tests;