[pve-devel] [PATCH pve-common 2/2] INotify.pm - new helper poll_changes

Dietmar Maurer dietmar at proxmox.com
Mon Jan 22 12:12:41 CET 2018


Useful to detect file changes.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/INotify.pm | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 1e5687b..445c034 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -199,6 +199,16 @@ sub discard_changes {
     return read_file ($filename, $full);
 }
 
+sub poll_changes {
+    my ($filename) = @_;
+
+    poll() if $inotify; # read new inotify events
+
+    $versions->{$filename} = 0 if !defined ($versions->{$filename});
+
+    return $versions->{$filename};
+}
+
 sub read_file {
     my ($fileid, $full) = @_;
 
@@ -211,11 +221,7 @@ sub read_file {
     my $fd;
     my $shadow;
 
-    poll() if $inotify; # read new inotify events
-
-    $versions->{$filename} = 0 if !defined ($versions->{$filename});
-
-    my $cver = $versions->{$filename};
+    my $cver = poll_changes($filename);
 
     if (my $copy = $shadowfiles->{$filename}) {
 	if ($fd = IO::File->new ($copy, "r")) {
-- 
2.11.0





More information about the pve-devel mailing list