This file is indexed.

/usr/lib/obs/server/bs_deltastore is in obs-server 2.7.1-10.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/perl -w
#
# Copyright (c) 2016 SUSE LLC.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
#
# The source delta generator.
#

BEGIN {
  my ($wd) = $0 =~ m-(.*)/- ;
  $wd ||= '.';
  unshift @INC,  "$wd/build";
  unshift @INC,  "$wd";
}

use XML::Structured ':bytes';
use POSIX;
use Fcntl qw(:DEFAULT :flock);
use Digest::MD5 ();

use BSConfiguration;
use BSUtil;
use BSSolv;

use strict;

my $bsdir = $BSConfig::bsdir || "/srv/obs";

BSUtil::mkdir_p_chown($bsdir, $BSConfig::bsuser, $BSConfig::bsgroup);
BSUtil::drop_privs_to($BSConfig::bsuser||$BSConfig::bsuser, $BSConfig::bsgroup||$BSConfig::bsgroup);
BSUtil::set_fdatasync_before_rename() unless $BSConfig::disable_data_sync || $BSConfig::disable_data_sync;

my $eventdir = "$BSConfig::bsdir/events";
my $srcrep = "$BSConfig::bsdir/sources";
my $uploaddir = "$BSConfig::bsdir/upload";
my $rundir = $BSConfig::rundir || "$BSConfig::bsdir/run";

my $myeventdir = "$eventdir/deltastore";

my $testmode;

sub deltastore {
  my ($projid, $packid, $file) = @_;
  print "generating src delta for $projid/$packid/$file\n";
  mkdir_p($uploaddir);
  my $tmp = "$uploaddir/deltastore.$$";
  unlink($tmp);
  unlink("$tmp.in");
  die("cannot get rid of $tmp") if -e $tmp;
  link("$srcrep/$packid/$file", "$tmp.in") || die("link $srcrep/$packid/$file $tmp.in: $!\n");
  if (BSSolv::isobscpio("$tmp.in")) {
    print "  - already delta cpio\n";
    unlink("$tmp.in");
    return;
  }
  if (!BSSolv::makeobscpio("$tmp.in", "$srcrep/$packid/deltastore", $tmp)) {
    print "  - delta creation error\n";
    unlink("$tmp.in");
    unlink($tmp);
    return;
  }
  unlink("$tmp.in");
  if (1) {
    if ($file =~ /^([0-9a-f]{32})-/) {
      my $md5 = $1;
      print "  - verifying re-expansion...\n";
      local *F;
      BSSolv::obscpioopen($tmp, "$srcrep/$packid/deltastore", \*F, $uploaddir) || die("BSSolv::obscpioopen failed\n");
      my $ctx = Digest::MD5->new;
      $ctx->addfile(*F);
      close F;
      my $rmd5 = $ctx->hexdigest();
      die("  - md5sum mismatch: $md5 $rmd5\n") if $md5 ne $rmd5;
    }
  }
  if (!rename($tmp, "$srcrep/$packid/$file")) {
    print "  - rename $tmp $srcrep/$packid/$file: $!\n";
    unlink("$tmp.in");
    unlink($tmp);
    return;
  }
}

if (@ARGV && ($ARGV[0] eq '--test-mode' || $ARGV[0] eq '--testmode')) {
  $testmode = 1;
  shift @ARGV;
}

$| = 1;
$SIG{'PIPE'} = 'IGNORE';
BSUtil::restartexit($ARGV[0], 'deltastore', "$rundir/bs_deltastore", "$myeventdir/.ping");
print "starting source delta generator\n";

mkdir_p($rundir);
open(RUNLOCK, '>>', "$rundir/bs_deltastore.lock") || die("$rundir/bs_deltastore.lock: $!\n");
flock(RUNLOCK, LOCK_EX | LOCK_NB) || die("deltastore is already running!\n");
utime undef, undef, "$rundir/bs_deltastore.lock";

mkdir_p($myeventdir);
if (!-p "$myeventdir/.ping") {
  POSIX::mkfifo("$myeventdir/.ping", 0666) || die("$myeventdir/.ping: $!");
  chmod(0666, "$myeventdir/.ping");
}
sysopen(PING, "$myeventdir/.ping", POSIX::O_RDWR) || die("$myeventdir/.ping: $!");

while(1) {
  # drain ping pipe
  my $dummy;
  fcntl(PING,F_SETFL,POSIX::O_NONBLOCK);
  1 while (sysread(PING, $dummy, 1024, 0) || 0) > 0;
  fcntl(PING,F_SETFL,0);

  # check for events
  my @events = ls($myeventdir);
  @events = grep {!/^\./} @events;
  for my $event (@events) {
    last if -e "$rundir/bs_deltastore.exit";
    last if -e "$rundir/bs_deltastore.restart";
    my $ev = readxml("$myeventdir/$event", $BSXML::event, 1);
    if (!$ev || !$ev->{'type'} || $ev->{'type'} ne 'deltastore') {
      unlink("$myeventdir/$event");
      next;
    }
    if (!defined($ev->{'project'}) || !defined($ev->{'package'}) || !defined($ev->{'job'})) {
      unlink("$myeventdir/$event");
      next;
    }
    eval {
      deltastore($ev->{'project'}, $ev->{'package'}, $ev->{'job'});
    };
    if ($@) {
      warn($@);
    } else {
      unlink("$myeventdir/$event");
    }
  }

  if ($testmode) {
    close(RUNLOCK);
    print "Test mode, exiting...\n";
    exit(0);
  }

  # check for restart/exit
  if (-e "$rundir/bs_deltastore.exit") {
    close(RUNLOCK);
    unlink("$rundir/bs_deltastore.exit");
    print "exiting...\n";
    exit(0);
  }
  if (-e "$rundir/bs_deltastore.restart") {
    close(RUNLOCK);
    unlink("$rundir/bs_deltastore.restart");
    print "restarting...\n";
    exec($0);
    die("$0: $!\n");
  }
  print "waiting for an event...\n";
  sysread(PING, $dummy, 1, 0);
}