]> git.proxmox.com Git - pve-manager.git/commitdiff
hw-address: check if source file changed so cache needs update
authorMaximiliano Sandoval <m.sandoval@proxmox.com>
Mon, 9 Oct 2023 09:35:58 +0000 (11:35 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 9 Oct 2023 14:36:59 +0000 (16:36 +0200)
We cache the hash of this file, it makes sense to first check if the
file changed via `stat` and recompute the hash if needed.

This mirrors similar changes done for PMG [0].

[0]: https://git.proxmox.com/?p=pmg-api.git;a=commit;h=16d2ff9f8e90db64114a66d78672f5a03f5ee990.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
PVE/API2Tools.pm

index a3d7ca84cd3f9d5eee6d4bdd3f6791fb457f005c..618c13b3938058af7d4a658f61a02c3689f6f4a5 100644 (file)
@@ -17,14 +17,22 @@ use PVE::SafeSyslog;
 use PVE::Storage::Plugin;
 
 my $hwaddress;
+my $hwaddress_st = {};
 
 sub get_hwaddress {
+    my $fn = '/etc/ssh/ssh_host_rsa_key.pub';
+    my $st = stat($fn);
 
-    return $hwaddress if defined ($hwaddress);
+    if (defined($hwaddress)
+       && $hwaddress_st->{mtime} == $st->mtime
+       && $hwaddress_st->{ino} == $st->ino
+       && $hwaddress_st->{dev} == $st->dev) {
+       return $hwaddress;
+    }
 
-    my $fn = '/etc/ssh/ssh_host_rsa_key.pub';
     my $sshkey = PVE::Tools::file_get_contents($fn);
     $hwaddress = uc(md5_hex($sshkey));
+    $hwaddress_st->@{'mtime', 'ino', 'dev'} = ($st->mtime, $st->ino, $st->dev);
 
     return $hwaddress;
 }