Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / modules / installer / filelists.pm
blobbf9dc2fb235a5016135775b0b71af0f0bdf6e6cd
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 package installer::filelists;
11 use File::stat;
13 use installer::files;
14 use installer::globals;
15 use installer::logger;
16 use installer::pathanalyzer;
18 sub resolve_filelist_flag
20 my ($files, $links, $outdir) = @_;
21 my @newfiles = ();
23 foreach my $file (@{$files})
25 my $is_filelist = 0;
26 my $use_internal_rights = 0;
27 if ($file->{'Styles'})
29 if ($file->{'Styles'} =~ /\bFILELIST\b/)
31 $is_filelist = 1;
33 if ($file->{'Styles'} =~ /\bUSE_INTERNAL_RIGHTS\b/ && !$installer::globals::iswin)
35 $use_internal_rights = 1;
39 if ($is_filelist)
41 my $filelist_path = $file->{'sourcepath'};
42 my $filelist = read_filelist($filelist_path);
43 if (@{$filelist})
45 my $destination = $file->{'destination'};
46 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
48 foreach my $path (@{$filelist})
50 my $is_symlink = 0;
52 if ((index $path, $outdir) != 0)
54 installer::logger::print_error("file '$path' is not in '$outdir'");
56 if (-l $path)
58 $is_symlink = 1;
60 else
62 if (!-e $path)
64 installer::logger::print_error("file '$path' does not exist");
68 my $subpath = substr $path, ((length $outdir) + 1); # drop separator too
70 my %newfile = ();
71 %newfile = %{$file};
72 $newfile{'Name'} = $subpath;
73 $newfile{'sourcepath'} = $path;
74 $newfile{'destination'} = $destination . $subpath;
75 $newfile{'filelistname'} = $file->{'Name'};
76 $newfile{'filelistpath'} = $file->{'sourcepath'};
78 if ($is_symlink)
80 # FIXME: for symlinks destination is mangled later in
81 # get_Destination_Directory_For_Item_From_Directorylist
82 $newfile{'DoNotMessWithSymlinks'} = 1;
83 $newfile{'Target'} = readlink($path);
84 push ( @{$links}, \%newfile );
86 else
88 if ($use_internal_rights)
90 my $st = stat($path);
91 $newfile{'UnixRights'} = sprintf("%o", $st->mode & 0777);
94 push @newfiles, \%newfile;
98 else
100 installer::logger::print_message("filelist $filelist_path is empty\n");
103 else # not a filelist, just pass the current file over
105 push @newfiles, $file;
109 return (\@newfiles, $links);
112 sub read_filelist
114 my ($path) = @_;
115 my $content = installer::files::read_file($path);
116 my @filelist = ();
118 foreach my $line (@{$content})
120 chomp $line;
121 foreach my $file (split /\s+/, $line)
123 if ($file ne "")
125 push @filelist, $file;
130 return \@filelist;
135 # vim: set expandtab shiftwidth=4 tabstop=4: