Changeset 332
- Timestamp:
- 01/23/11 10:55:48 (13 years ago)
- Location:
- server/trunk/web
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
server/trunk/web/bin/sophie_scan
r42 r332 3 3 use strict; 4 4 use warnings; 5 use Sophie::Base;6 use Sophie::Base::RpmsPath;7 5 use Linux::Inotify2; 8 6 use POSIX ":sys_wait_h"; 9 7 use Getopt::Long; 8 9 $ENV{LC_ALL} = 'C'; 10 require Sophie::Base; 11 require Sophie::Base::RpmsPath; 10 12 11 13 GetOptions( … … 18 20 my %modified_paths; 19 21 my $inotify = undef; 20 $updated_inotify ||= 300;22 $updated_inotify ||= 500; 21 23 22 24 if ($daemon) { … … 29 31 while (1) { 30 32 local $SIG{ALRM} = sub { 31 $inotify = undef;32 warn "reparse paths";33 33 alarm($updated_inotify); 34 34 }; … … 36 36 %modified_paths = (); 37 37 } 38 $inotify ||= inotify_path(); 38 warn "$$ Inotify"; 39 $inotify = inotify_path(); 39 40 $inotify->poll; 40 41 } … … 68 69 return; 69 70 } 70 warn "updating base"; 71 72 my @pkey; 73 { 74 my $sophie = Sophie::Base->connect or do { 75 die "cannot read config file\n"; 76 }; 77 @pkey = $sophie->resultset('Paths')->search( 78 path => [ @path ], 79 )->get_column('d_path_key')->all; 80 push(@pkey, $sophie->resultset('Paths')->search({ 81 updated => [ undef, 82 \[ " < now() - '6 hours'::interval"], 83 ], 84 })->get_column('d_path_key')->all); 85 my %uniq = map { $_ => 1 } @pkey; 86 @pkey = keys %uniq; 87 } 88 89 return 1 if (!@pkey); 90 71 warn "$$ updating base"; 91 72 if (my $pid = fork()) { 92 73 } else { 93 74 75 alarm 0; 76 my @pkey; 77 { 78 my $sophie = Sophie::Base->connect or do { 79 die "cannot read config file\n"; 80 }; 81 @pkey = $sophie->resultset('Paths')->search( 82 path => [ @path ], 83 )->get_column('d_path_key')->all; 84 push(@pkey, $sophie->resultset('Paths')->search({ 85 updated => [ undef, 86 \[ " < now() - '24 hours'::interval"], 87 ], 88 })->get_column('d_path_key')->all); 89 my %uniq = map { $_ => 1 } @pkey; 90 @pkey = keys %uniq; 91 } 94 92 95 my $NB_PAR = 2; 93 exit(0) if (!@pkey); 94 95 96 97 my $NB_PAR = 1; 96 98 my @split; 97 99 my $div = @pkey / $NB_PAR; … … 108 110 109 111 foreach my $pathkey (@{ $job }) { 110 my @delta = Sophie::Base::RpmsPath->new($pathkey) 112 my $time = time; 113 my @delta = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect) 111 114 ->find_delta; 112 115 while (my @d = splice(@delta, 0, 25)) { 113 my $path = Sophie::Base::RpmsPath->new($pathkey );116 my $path = Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect); 114 117 $path->update_content(@d); 115 $path->db->disconnect; 118 #$path->db->disconnect; 119 # If it take too long time, next path 120 last if (time > $time + 15 * 60); 116 121 } 117 Sophie::Base::RpmsPath->new($pathkey)->set_updated; 122 Sophie::Base::RpmsPath->new($pathkey, Sophie::Base->connect)->set_updated 123 if (!@delta); # update only if we finished 118 124 } 119 125 exit(0); -
server/trunk/web/lib/Sophie/Base.pm
r42 r332 29 29 $connect_info->{user} = $config->{dbuser}; 30 30 $connect_info->{password} = $config->{dbpassword}; 31 $connect_info->{unsafe} = 1; 31 32 } 33 $connect_info->{PrintError} = 0; 34 $connect_info->{RaiseError} = 0; 32 35 exists($connect_info->{AutoCommit}) or $connect_info->{AutoCommit} = 0; 33 36 $class->SUPER::connection( -
server/trunk/web/lib/Sophie/Base/Header.pm
r42 r332 11 11 12 12 sub new { 13 my ($class, $pkgid ) = @_;13 my ($class, $pkgid, $db) = @_; 14 14 15 bless({ key => $pkgid }, $class);15 bless({ key => $pkgid, db => $db }, $class); 16 16 } 17 17 18 18 sub key { $_[0]->{key} } 19 sub db { 20 $_[0]->{db}->storage->dbh 21 } 19 22 20 23 sub rpm_path { … … 59 62 my $add_content = $self->db->prepare_cached( 60 63 q{ 61 UPDATE allfiles set contents = ? where pkgid = ? and count = ?64 UPDATE allfiles set contents = ?, has_content = ? where pkgid = ? and count = ? 62 65 } 63 66 ); … … 69 72 sub { 70 73 my ($file) = @_; 71 my ($dirname, $basename) = $file->name =~ /^(?:\.(.*\/))?([^\/]+)$/; 72 $dirname ||= ''; 73 my $entry = $files->{$dirname}{$basename}; 74 my $fname = $file->name; 75 $fname =~ s/^\.\///; 76 my ($dirname, $basename) = $fname =~ /^(.*\/)?([^\/]+)$/; 77 $dirname = $rpm =~ /src.rpm$/ 78 ? '' 79 : $dirname ? "/$dirname" : '' ; 80 my $entry = $files->{$dirname}{$basename} or do { 81 warn "unknown $dirname, $basename"; 82 return 1; 83 }; 74 84 for (1) { 75 $entry->{size} > 1024 * 1024 and return 1; 85 $entry->{flags} == 32 and last; 86 my $maxsize = $dirname eq '' ? 2 * 1024 : 50; 87 $entry->{size} > $maxsize * 1024 and return 1; 88 $basename =~ /\.gz$/ and return; 76 89 # Spec files and patch 77 $entry->{flags} == 32 and last;78 90 $dirname eq '' and last; 79 91 # Doc files … … 86 98 return 1; 87 99 } 88 my $ content = $file->get_content;89 my $enc = guess_encoding($ content, qw/latin1/);100 my $rawcontent = $file->get_content; 101 my $enc = guess_encoding($rawcontent, qw/latin1/); 90 102 if ($enc && ref $enc) { 91 $content = $enc->decode($content);103 my $content = $enc->decode($rawcontent); 92 104 93 105 $self->db->pg_savepoint('FILECONTENT'); 94 106 $add_content->execute( 95 $enc && ref $enc ? encode('utf8', $enc->decode($content)) : $content, 107 $enc && ref $enc ? encode('utf8', $content) : $rawcontent, 108 1, 96 109 $self->key, 97 110 $entry->{count}) or do { 98 $self->db->pg_rollback_to('FILECONTENT'); 99 }; 100 } else { 101 } 111 $self->db->pg_rollback_to('FILECONTENT'); 112 }; 113 } 102 114 1; 103 115 } -
server/trunk/web/lib/Sophie/Base/RpmsPath.pm
r42 r332 11 11 use Encode::Guess; 12 12 use Encode; 13 use Time::HiRes; 13 14 14 15 sub new { 15 my ($class, $pathkey) = @_; 16 17 bless({ key => $pathkey }, $class); 18 } 19 20 sub key { $_[0]->{key} } 16 my ($class, $pathkey, $db) = @_; 17 18 bless({ key => $pathkey, db => $db }, $class); 19 } 20 21 sub key { $_[0]->{key} } 22 sub db { 23 $_[0]->{db}->storage->dbh 24 } 21 25 22 26 sub path { … … 62 66 my ($self) = @_; 63 67 64 warn $self->path; 65 66 my $localrpms = $self->local_ls_rpms || {}; 68 warn "$$ " . $self->path; 69 70 my @delta; 71 my $localrpms = $self->local_ls_rpms; 67 72 my $baserpms = $self->ls_rpms; 68 73 74 if ($localrpms) { 75 push(@delta, { delta => 'DE' }); 76 } else { 77 push(@delta, { delta => 'DM' }); 78 } 79 80 69 81 my %list; 70 foreach (keys %{ $localrpms }, keys %{ $baserpms }) {82 foreach (keys %{ $localrpms || {} }, keys %{ $baserpms }) { 71 83 $list{$_} = 1; 72 84 } 73 my @delta;74 85 75 86 foreach my $rpm (sort { $b cmp $a } keys %list) { … … 91 102 elsif ($_->{delta} eq 'A') { 92 103 $self->add_rpm($_->{rpm}); 104 #sleep(1); 105 #Time::HiRes::usleep(750); 93 106 } 94 107 elsif ($_->{delta} eq 'R') { 95 108 $self->remove_rpm($_->{rpm}); 96 } 97 } 109 } elsif ($_->{delta} eq 'DM') { 110 $self->set_exists(0); 111 } elsif ($_->{delta} eq 'DE') { 112 $self->set_exists(1); 113 } 114 } 115 } 116 117 sub set_exists { 118 my ($self, $exists) = @_; 119 $self->db->prepare_cached(q{ 120 update d_path set exists = ? where d_path_key = ? 121 })->execute(($exists ? 1 : 0), $self->key); 122 $self->db->commit; 98 123 } 99 124 100 125 sub set_updated { 101 126 my ($self) = @_; 102 warn " UPD";127 warn "$$ UPD"; 103 128 $self->db->prepare_cached(q{ 104 129 update d_path set updated = now() where d_path_key = ? … … 110 135 sub remove_rpm { 111 136 my ($self, $rpm) = @_; 137 warn "$$ deleting $rpm"; 112 138 my $remove = $self->db->prepare_cached( 113 139 q{ … … 117 143 for (1 .. 3) { 118 144 if ($remove->execute($self->key, $rpm)) { 119 warn "deleting $rpm";120 145 $self->db->commit; 121 146 return 1; … … 128 153 my ($self, $rpm) = @_; 129 154 155 warn "$$ adding $rpm"; 130 156 for (1 .. 3) { 131 157 if (defined(my $pkgid = $self->_add_header($rpm))) { … … 137 163 } 138 164 ); 139 if ($register->execute($self->key, $rpm, $pkgid)) { 140 warn "adding $rpm"; 165 $register->execute($self->key, $rpm, $pkgid) and do { 141 166 $self->db->commit; 142 return ;167 return 1; 143 168 } 144 169 … … 153 178 my $header; 154 179 eval { 155 $header = RPM4::Header->new($self->path . '/' . $rpm )180 $header = RPM4::Header->new($self->path . '/' . $rpm, $self->{db}) 156 181 }; 157 182 $header or do { 158 warn " Cannot read " . $self->path . '/' . $rpm;183 warn "$$ Cannot read " . $self->path . '/' . $rpm; 159 184 return ""; 160 185 }; … … 168 193 $find->finish; 169 194 if ($rows) { 170 warn " Find";195 warn "$$ Find"; 171 196 return $header->queryformat('%{PKGID}'); 172 197 } … … 181 206 my $add_header = $self->db->prepare_cached( 182 207 q{ 183 INSERT into rpms (pkgid, name, header, evr, issrc, description, summary)184 values (?,?,rpmheader_in(decode(?, 'hex')::bytea),?,?,?,? )208 INSERT into rpms (pkgid, name, header, evr, arch, issrc, description, summary) 209 values (?,?,rpmheader_in(decode(?, 'hex')::bytea),?,?,?,?,?) 185 210 } 186 211 ); … … 201 226 unpack('H*', $string), 202 227 $header->queryformat('%|EPOCH?{%{EPOCH}:}:{}|%{VERSION}-%{RELEASE}'), 228 $header->queryformat('%{ARCH}'), 203 229 $header->hastag('SOURCERPM') ? 'f' : 't', 204 230 $description, 205 231 $summary, 206 ) ;232 ) or return; 207 233 my $index_tag = $self->db->prepare_cached( 208 234 q{ … … 212 238 $index_tag->execute($header->queryformat('%{PKGID}')) or return; 213 239 $index_tag->finish; 214 Sophie::Base::Header->new($header->queryformat('%{PKGID}')) 215 ->addfiles_content({ path => $self->path, filename => $rpm}) or return; 240 if (!$header->hastag('SOURCERPM')) { 241 Sophie::Base::Header->new($header->queryformat('%{PKGID}'), $self->{db}) 242 ->addfiles_content({ path => $self->path, filename => $rpm}) or return; 243 } 216 244 217 245 $header->queryformat('%{PKGID}');
Note: See TracChangeset
for help on using the changeset viewer.