-
Notifications
You must be signed in to change notification settings - Fork 10
bug: rename() breaks open file handles — reads return EOF, writes warn #347
Copy link
Copy link
Open
Description
Summary
After rename('/old', '/new'), any filehandle opened on /old loses access to the file data. Reads return EOF (0 bytes), writes produce uninitialized-value warnings, and eof() triggers warnings.
Reproduction
use Test::MockFile qw(nostrict);
my $old = Test::MockFile->file('/tmp/old.txt', 'Hello World');
my $new = Test::MockFile->file('/tmp/new.txt', '');
open my $fh, '<', '/tmp/old.txt' or die;
read($fh, my $buf, 5); # "Hello" — works fine
rename('/tmp/old.txt', '/tmp/new.txt');
read($fh, $buf, 6); # Should be " World", gets EOF (0)
# Warning: Use of uninitialized value $contents_len in numeric ge (>=)Expected behavior
Open file descriptors follow the inode (Unix semantics). After rename, the handle should continue reading/writing the data at its new location.
Root cause
The tied FileHandle object stores a weak data ref to $files_being_mocked{'/tmp/old.txt'}. When __rename transfers contents to the new mock, it sets $mock_old->{'contents'} = undef — but the handle's data still points to the old mock.
Fix
PR #346
🤖 Created by Kōan from autonomous session
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels