mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-06-12 12:51:25 +00:00
46 lines
790 B
Perl
46 lines
790 B
Perl
package Proxmox::Sys::File;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use IO::File;
|
|
|
|
use base qw(Exporter);
|
|
our @EXPORT_OK = qw(file_read_firstline file_read_all file_write_all);
|
|
|
|
sub file_read_firstline {
|
|
my ($filename) = @_;
|
|
|
|
my $fh = IO::File->new ($filename, "r");
|
|
return undef if !$fh;
|
|
|
|
my $res = <$fh>;
|
|
chomp $res if $res;
|
|
$fh->close;
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
sub file_read_all {
|
|
my ($filename) = @_;
|
|
|
|
my $fh = IO::File->new($filename, "r") || die "can't open '$filename' - $!\n";
|
|
|
|
local $/; # slurp mode
|
|
my $content = <$fh>;
|
|
close $fh;
|
|
|
|
return $content;
|
|
}
|
|
|
|
sub file_write_all {
|
|
my ($filename, $content) = @_;
|
|
|
|
my $fd = IO::File->new(">$filename") || die "unable to open file '$filename' - $!\n";
|
|
print $fd $content;
|
|
$fd->close();
|
|
}
|
|
|
|
1;
|