Subject: | Watcher blocking rename on new files |
The Watcher recognices when a new file has been created. However, it
does also block access to that file. It is possible to change the file's
content or even delete the file or folder - renaming it is not, though.
TEST:
use Win32::FileSystem::Watcher;
# disable output buffering as this script will never end
$|++;
my $watcher = Win32::FileSystem::Watcher->new(
"C:\\",
notify_filter => FILE_NOTIFY_ALL,
watch_sub_tree => 1,
);
$watcher->start();
# blocking
while ("true") {
print '.'; #have to do an output here as the following print would not
appear otherwise
sleep(5);
my @entries = $watcher->get_results();
foreach my $entry (@entries) {
print "\n" . $entry->action_name . " " . $entry->file_name . "\n";
}
}
ENVIRONMENT:
I'm using Perl "v5.10.0 built for MSWin32-x86-multi-thread" on a Win XP
Pro SP 3.
SOLUTION:
It seems this is related to the directory handle created in
Win32::FileSystem::Watcher::Synchronous and it's method _create_file in
line 143 ff. The handle is created with FILE_SHARE_READ |
FILE_SHARE_DELETE. Is there a reason not to include the FILE_SHARE_WRITE
option that would allow renaming of the file directly after creation?
Of course, this is related to me not using the stop() and start()
methods everytime file changes happen. As there could be file changes
lost while restarting the Watcher I'd like to keep it that way.