Changeset 7257


Ignore:
Timestamp:
May 27, 2004, 7:39:44 AM (16 years ago)
Author:
kevin
Message:

Detect and report conflicting submissions.

Location:
trunk/base/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portsubmit.tcl

    r7252 r7257  
    6666        set portsource ""
    6767        if {![catch {set fd [open ".dports_source" r]}]} {
    68                 set line [gets $fd]
    69                 regexp -- {^source: (.*)$} $line unused portsource
     68                while {[gets $fd line] != -1} {
     69                        regexp -- {^(.*): (.*)$} $line unused key value
     70                        switch -- $key {
     71                                source { set portsource $value }
     72                                revision { set base_rev $value }
     73                        }
     74                }
    7075                close $fd
    7176        }
     
    102107    append cmd "-F name=${portname} "
    103108    append cmd "-F version=${portversion} "
     109    append cmd "-F base_rev=${base_rev} "
    104110    append cmd "-F md5=[md5 file ${workpath}/Portfile.tar.gz] "
    105111    append cmd "-F attachment=@${workpath}/Portfile.tar.gz "
     
    112118    append cmd "-F \"master_sites=[shell_escape $master_sites]\" "
    113119
    114     #puts $cmd
     120    ui_debug $cmd
    115121    if {[system $cmd] != ""} {
    116122        return -code error [format [msgcat::mc "Failed to submit port : %s"] $portname]
  • trunk/base/src/portindex/portsubmit.pl

    r7252 r7257  
    9292my $name         = &validate_param(qr[^A-Za-z0-9_.-], $cgi->param('name'));
    9393my $version      = &validate_param(qr[^A-Za-z0-9_.-], $cgi->param('version'));
     94my $base_rev     = &validate_param(qr[^0-9], $cgi->param('base_rev'));
    9495my $md5          = &validate_param(qr[^A-Fa-f0-9], $cgi->param('md5'));
    9596my $submitted_by = &validate_param(qr[^A-Za-z0-9.!@#$%^&*_+=-],
     
    120121# value to the caller.
    121122#
    122 sub atomic_serial($) {
    123     my ($filename) = @_;
     123# The optional second parameter is used to detect
     124# conflicts.  If the existing serial does not equal
     125# the second parameter, then the serial is not
     126# updated and this function returns the existing
     127# serial number as a negative number.
     128#
     129sub atomic_serial($$) {
     130    my ($filename, $last_rev) = @_;
    124131    sysopen(SERIAL, $filename, O_RDWR|O_CREAT|O_EXLOCK) or die "Unable to open $filename: $!";
    125132    my $serial = <SERIAL>;
     133    chomp($serial);
    126134    if (!$serial) {
    127135        $serial = "1";
    128136    } else {
    129         $serial = $serial + 1;
     137        if (!defined($last_rev) or ($serial eq $last_rev)) {
     138            $serial = $serial + 1;
     139        } else {
     140            close(SERIAL);
     141            return -1 * $serial;
     142        }
    130143    }
    131144    # serials are monotonically increasing, so simply
     
    225238    }
    226239}
    227 $revision = &atomic_serial(".last_revision");
     240$revision = &atomic_serial(".last_revision", $base_rev);
     241
     242#
     243# If the new revision does not immediately follow the revision that the
     244# submission is based on, then someone else has submitted an intermediate
     245# change.  Therefore there is likely a conflict.  Report the conflict to the
     246# client, and indicate which revision the conflict must be resolved with.
     247#
     248
     249if ($revision < 0) {
     250    print "CONFLICT: $transaction\n";
     251    print "revision: ", -1 * $revision, "\n";
     252    exit;
     253}
    228254
    229255mkdir("$revision");
Note: See TracChangeset for help on using the changeset viewer.