summaryrefslogtreecommitdiff
path: root/solenv/bin/modules/installer/filelists.pm
blob: 8c0231a0d843cef97759306cfae976d61ddca3e1 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

package installer::filelists;

use File::stat;

use installer::files;
use installer::globals;
use installer::logger;
use installer::pathanalyzer;

sub resolve_filelist_flag
{
    my ($files, $links, $outdir) = @_;
    my @newfiles = ();

    foreach my $file (@{$files})
    {
        my $is_filelist = 0;
        my $use_internal_rights = 0;
        if ($file->{'Styles'})
        {
            if ($file->{'Styles'} =~ /\bFILELIST\b/)
            {
                $is_filelist = 1;
            }
            if ($file->{'Styles'} =~ /\bUSE_INTERNAL_RIGHTS\b/ && !$installer::globals::iswin)
            {
                $use_internal_rights = 1;
            }
        }

        if ($is_filelist)
        {
            my $filelist_path = $file->{'sourcepath'};
            my $filelist = read_filelist($filelist_path);
            if (@{$filelist})
            {
                my $destination = $file->{'destination'};
                installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);

                foreach my $path (@{$filelist})
                {
                    my $is_symlink = 0;

                    if ((index $path, $outdir) != 0)
                    {
                        installer::logger::print_error("file '$path' is not in '$outdir'");
                    }
                    if (-l $path)
                    {
                        $is_symlink = 1;
                    }
                    else
                    {
                        if (!-e $path)
                        {
                            installer::logger::print_error("file '$path' does not exist");
                        }
                    }

                    my $subpath = substr $path, ((length $outdir) + 1); # drop separator too

                    my %newfile = ();
                    %newfile = %{$file};
                    $newfile{'Name'} = $subpath;
                    $newfile{'sourcepath'} = $path;
                    $newfile{'destination'} = $destination . $subpath;
                    $newfile{'filelistname'} = $file->{'Name'};
                    $newfile{'filelistpath'} = $file->{'sourcepath'};

                    if ($is_symlink)
                    {
                        # FIXME: for symlinks destination is mangled later in
                        # get_Destination_Directory_For_Item_From_Directorylist
                        $newfile{'DoNotMessWithSymlinks'} = 1;
                        $newfile{'Target'} = readlink($path);
                        push @links, \%newfile;
                    }
                    else
                    {
                        if ($use_internal_rights)
                        {
                            my $st = stat($path);
                            $newfile{'UnixRights'} = sprintf("%o", $st->mode & 0777);
                        }

                        push @newfiles, \%newfile;
                    }
                }
            }
            else
            {
                installer::logger::print_message("filelist $filelist_path is empty\n");
            }
        }
        else # not a filelist, just pass the current file over
        {
            push @newfiles, $file;
        }
    }

    return (\@newfiles, \@links);
}

sub read_filelist
{
    my ($path) = @_;
    my $content = installer::files::read_file($path);
    my @filelist = ();

    foreach my $line (@{$content})
    {
        chomp $line;
        foreach my $file (split /\s+/, $line)
        {
            if ($file ne "")
            {
                push @filelist, $file;
            }
        }
    }

    return \@filelist;
}

1;

# vim: set expandtab shiftwidth=4 tabstop=4: