[pve-devel] r5018 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Aug 16 14:07:14 CEST 2010


Author: dietmar
Date: 2010-08-16 12:07:14 +0000 (Mon, 16 Aug 2010)
New Revision: 5018

Modified:
   pve-common/trunk/ChangeLog
   pve-common/trunk/Tools.pm
Log:
(file_read_firstline): new function to read first line of file -
	moved fron Storage.pm



Modified: pve-common/trunk/ChangeLog
===================================================================
--- pve-common/trunk/ChangeLog	2010-08-16 12:02:55 UTC (rev 5017)
+++ pve-common/trunk/ChangeLog	2010-08-16 12:07:14 UTC (rev 5018)
@@ -2,6 +2,8 @@
 
 	* Tools.pm (run_command): remove 'ticket' parameter - I think we
 	do not need it.
+	(file_read_firstline): new function to read first line of file -
+	moved fron Storage.pm
 
 	* RESTHandler.pm (handle): remove ugly $resp parameter - we can
 	now use the new Expection object to return better error info.

Modified: pve-common/trunk/Tools.pm
===================================================================
--- pve-common/trunk/Tools.pm	2010-08-16 12:02:55 UTC (rev 5017)
+++ pve-common/trunk/Tools.pm	2010-08-16 12:07:14 UTC (rev 5018)
@@ -13,6 +13,7 @@
 run_command 
 file_set_contents 
 file_get_contents
+file_read_firstline
 split_list
 safe_print
 );
@@ -113,6 +114,17 @@
     return $content;
 }
 
+sub file_read_firstline {
+    my ($filename) = @_;
+
+    my $fh = IO::File->new ($filename, "r");
+    return undef if !$fh;
+    my $res = <$fh>;
+    chomp $res;
+    $fh->close;
+    return $res;
+}
+
 sub safe_read_from {
     my ($fh, $max, $oneline) = @_;
 




More information about the pve-devel mailing list