Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Last active June 11, 2018 23:42
Show Gist options
  • Select an option

  • Save briandfoy/5aa3f680d9b684f611b8b9a98a56af04 to your computer and use it in GitHub Desktop.

Select an option

Save briandfoy/5aa3f680d9b684f611b8b9a98a56af04 to your computer and use it in GitHub Desktop.
=pod
I'm experiencing an odd problem on macOS 10.13. I suspect it's
something to do with APFS (Encrypted). It looks like there's some
other magic when I try to rename a file to a name that already exists.
I could not reproduce this on FAT or HFS+ filesystems.
I've tried this with perls back to 5.12, all compiled with clang
(4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)).
Start with a file named F<Changes> and no file named F<Changes.bak>.
=over 4
=item Run it the first time. You should end up with a F<Changes> and a F<Changes.bak>.
=item Run it again. You end up with F<Changes> and F<Changes 3> file. This is odd.
=item Run it again. You end up with a F<Changes> file, F<Changes.bak>, and F<Changes 3>.
=item Run it again. You end up with a F<Changes> file, F<Changes 3>, and F<Changes 4>.
=back
=cut
my $changes = "Changes";
my $bak = $changes . ".bak";
rename $changes, $bak or die "Could not backup $changes. $!\n";
open my $in, '<', $bak or die "Could not read old $changes file! $!\n";
open my $out, ">", $changes;
print {$out} 'Hello';
close $out;
close $in;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment