cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / solenv / bin / modules / installer / filelists.pm
blobb623478a30b8aaaf0e2bf2871f63bb6b1e965d6e
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 strict;
12 use warnings;
14 use File::stat;
16 use installer::files;
17 use installer::globals;
18 use installer::logger;
19 use installer::pathanalyzer;
21 sub resolve_filelist_flag
23 my ($files, $links, $outdir) = @_;
24 my @newfiles = ();
25 my $error = 0;
27 foreach my $file (@{$files})
29 my $is_filelist = 0;
30 my $use_internal_rights = 0;
31 if ($file->{'Styles'})
33 if ($file->{'Styles'} =~ /\bFILELIST\b/)
35 $is_filelist = 1;
37 if ($file->{'Styles'} =~ /\bUSE_INTERNAL_RIGHTS\b/ && !$installer::globals::iswin)
39 $use_internal_rights = 1;
43 if ($is_filelist)
45 my $filelist_path = $file->{'sourcepath'};
46 my $filelist = read_filelist($filelist_path);
47 if (@{$filelist})
49 my $destination = $file->{'destination'};
50 installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
52 foreach my $path (@{$filelist})
54 my $is_symlink = 0;
56 if ((index $path, $outdir) != 0)
58 installer::logger::print_error("file '$path' is not in '$outdir'");
59 $error = 1;
61 if ($path =~ '\/\/')
63 installer::logger::print_error("file '$path' contains 2 consecutive '/' which breaks MSIs");
64 $error = 1;
66 if (-l $path)
68 $is_symlink = 1;
70 else
72 if (!-e $path)
74 installer::logger::print_error("file '$path' does not exist");
75 $error = 1;
79 my $subpath = substr $path, ((length $outdir) + 1); # drop separator too
81 my %newfile = ();
82 %newfile = %{$file};
83 $newfile{'Name'} = $subpath;
84 $newfile{'sourcepath'} = $path;
85 $newfile{'destination'} = $destination . $subpath;
86 $newfile{'filelistname'} = $file->{'Name'};
87 $newfile{'filelistpath'} = $file->{'sourcepath'};
89 if ($is_symlink)
91 # FIXME: for symlinks destination is mangled later in
92 # get_Destination_Directory_For_Item_From_Directorylist
93 $newfile{'DoNotMessWithSymlinks'} = 1;
94 $newfile{'Target'} = readlink($path);
95 push ( @{$links}, \%newfile );
97 else
99 if ($use_internal_rights)
101 my $st = stat($path);
102 $newfile{'UnixRights'} = sprintf("%o", $st->mode & 0777);
105 push @newfiles, \%newfile;
109 else
111 installer::logger::print_message("filelist $filelist_path is empty\n");
114 else # not a filelist, just pass the current file over
116 push @newfiles, $file;
120 if ( $error )
122 installer::exiter::exit_program("ERROR: error(s) in resolve_filelist_flag");
125 return (\@newfiles, $links);
128 sub read_filelist
130 my ($path) = @_;
131 my $content = installer::files::read_file($path);
132 my @filelist = ();
134 # split on space, but only if followed by / (don't split within a filename)
135 my $splitRE = qr!\s+(?=/)!;
136 # filelist on win have C:/cygwin style however - also reading dos-file under
137 # cygwin retains \r\n - so chomp below still leaves \r to strip in the RE
138 $splitRE = qr!\s+(?:$|(?=[A-Z]:/))! if ($installer::globals::os eq "WNT");
140 foreach my $line (@{$content})
142 chomp $line;
143 foreach my $file (split $splitRE, $line)
145 if ($file ne "")
147 push @filelist, $file;
152 return \@filelist;
157 # vim: set expandtab shiftwidth=4 tabstop=4: