Annotation of /trunk/mozilla/patches/mozilla-rebuild-databases.pl
Parent Directory | Revision Log
Revision 153 -
(hide annotations)
(download)
Tue May 8 20:52:56 2007 UTC (17 years, 5 months ago) by niro
File MIME type: text/plain
File size: 2310 byte(s)
Tue May 8 20:52:56 2007 UTC (17 years, 5 months ago) by niro
File MIME type: text/plain
File size: 2310 byte(s)
-import
1 | niro | 153 | #!/usr/bin/perl |
2 | |||
3 | use File::Path; | ||
4 | use File::Copy; | ||
5 | use File::Glob ":glob"; | ||
6 | use POSIX ":sys_wait_h"; | ||
7 | |||
8 | $timeout = 60; | ||
9 | |||
10 | %{ENV}->{"MOZILLA_FIVE_HOME"}="/usr/lib/mozilla"; | ||
11 | %{ENV}->{"LD_LIBRARY_PATH"}="/usr/lib/mozilla"; | ||
12 | |||
13 | umask 022; | ||
14 | |||
15 | if ( -f "/usr/lib/mozilla/regxpcom" ) | ||
16 | { | ||
17 | # remove all of the old files | ||
18 | rmtree("/usr/lib/mozilla/chrome/overlayinfo"); | ||
19 | unlink </usr/lib/mozilla/chrome/*.rdf>; | ||
20 | unlink("/usr/lib/mozilla/component.reg"); | ||
21 | unlink("/usr/lib/mozilla/components/compreg.dat"); | ||
22 | unlink("/usr/lib/mozilla/components/xpti.dat"); | ||
23 | |||
24 | # create a new clean path | ||
25 | mkpath("/usr/lib/mozilla/chrome/overlayinfo"); | ||
26 | |||
27 | # rebuild the installed-chrome.txt file from the installed | ||
28 | # languages | ||
29 | if ( -f "/usr/lib/mozilla/chrome/lang/installed-chrome.txt" ) { | ||
30 | rebuild_lang_files(); | ||
31 | } | ||
32 | |||
33 | # run regxpcom | ||
34 | $pid = fork(); | ||
35 | |||
36 | # I am the child. | ||
37 | if ($pid == 0) { | ||
38 | exec("/usr/lib/mozilla/regxpcom > /dev/null 2> /dev/null"); | ||
39 | } | ||
40 | # I am the parent. | ||
41 | else { | ||
42 | my $timepassed = 0; | ||
43 | do { | ||
44 | $kid = waitpid($pid, &WNOHANG); | ||
45 | sleep(1); | ||
46 | $timepassed++; | ||
47 | } until $kid == -1 || $timepassed > $timeout; | ||
48 | |||
49 | # should we kill? | ||
50 | if ($timepassed > $timeout) { | ||
51 | kill (9, $pid); | ||
52 | # kill -9 can leave threads hanging around | ||
53 | system("/usr/bin/killall -9 regxpcom"); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | # and run regchrome for good measure | ||
58 | $pid = fork(); | ||
59 | |||
60 | # I am the child. | ||
61 | if ($pid == 0) { | ||
62 | exec("/usr/lib/mozilla/regchrome > /dev/null 2> /dev/null"); | ||
63 | } | ||
64 | # I am the parent. | ||
65 | else { | ||
66 | my $timepassed = 0; | ||
67 | do { | ||
68 | $kid = waitpid($pid, &WNOHANG); | ||
69 | sleep(1); | ||
70 | $timepassed++; | ||
71 | } until $kid == -1 || $timepassed > $timeout; | ||
72 | |||
73 | # should we kill? | ||
74 | if ($timepassed > $timeout) { | ||
75 | kill (9, $pid); | ||
76 | # kill -9 can leave threads hanging around | ||
77 | system("/usr/bin/killall -9 regchrome"); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | } | ||
82 | |||
83 | |||
84 | sub rebuild_lang_files { | ||
85 | unlink("/usr/lib/mozilla/chrome/installed-chrome.txt"); | ||
86 | |||
87 | open (OUTPUT, "+>", "/usr/lib/mozilla/chrome/installed-chrome.txt")|| | ||
88 | die("Failed to open installed-chrome.txt: $!\n"); | ||
89 | |||
90 | copy("/usr/lib/mozilla/chrome/lang/installed-chrome.txt", | ||
91 | \*OUTPUT); | ||
92 | |||
93 | foreach (bsd_glob("/usr/lib/mozilla/chrome/lang/lang-*.txt")) { | ||
94 | copy($_, \*OUTPUT); | ||
95 | } | ||
96 | |||
97 | copy("/usr/lib/mozilla/chrome/lang/default.txt", | ||
98 | \*OUTPUT); | ||
99 | } |