public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob bd1c4e9236a7482851df3205df35449604d266b3 922 bytes (raw)
$ git show HEAD:t/rename_noreplace.t	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
#!perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use v5.10.1;
use PublicInbox::TestCommon;
use_ok 'PublicInbox::Syscall', 'rename_noreplace';
my ($tmpdir, $for_destroy) = tmpdir;

open my $fh, '>', "$tmpdir/a" or xbail $!;
my @sa = stat($fh);
is(rename_noreplace("$tmpdir/a", "$tmpdir/b"), 1, 'rename_noreplace');
my @sb = stat("$tmpdir/b");
ok(scalar(@sb), 'new file exists');
ok(!-e "$tmpdir/a", 'original gone');
is("@sa[0,1]", "@sb[0,1]", 'same st_dev + st_ino');

is(rename_noreplace("$tmpdir/a", "$tmpdir/c"), undef, 'undef on ENOENT');
ok($!{ENOENT}, 'ENOENT set when missing');

open $fh, '>', "$tmpdir/a" or xbail $!;
is(rename_noreplace("$tmpdir/a", "$tmpdir/b"), undef, 'undef on EEXIST');
ok($!{EEXIST}, 'EEXIST set when missing');
is_deeply([stat("$tmpdir/b")], \@sb, 'target unchanged on EEXIST');

done_testing;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git