aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Iurt/File.pm
blob: 7f28628a4c0b4865a0071d77a9567bb64278bab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Iurt::File;

use base qw(Exporter);
use Iurt::Config qw(get_mandatory_arch);
use File::Copy 'move';
use File::Path 'make_path';
use Iurt::Util qw(plog);
use MDK::Common qw(cat_ find member partition);
use strict;

our @EXPORT = qw(
    create_file
    check_file_timeout
    read_line
);

sub create_file {
    my $file = shift;
    my @contents = @_;

    open my $FILE, ">$file" or die "FATAL: can't open $file for writing";
    print $FILE "@contents";
}

sub check_file_timeout {
    my ($file, $time) = @_;

    my $i = 0;
    while ($i < $time && (!-f $file || -z $file)) { sleep 1; $i++ }

    $i == $time;
}

sub read_line {
    my $file = shift;

    open my $FILE, "<$file" or die "FATAL: can't open $file for reading";
    my $contents = <$FILE>;

    $contents;
}