Indefero

Indefero Commit Details


Date:2010-09-14 17:30:28 (14 years 3 months ago)
Author:Thomas Keller
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:36a58dcae2eba1f82f5568281bb9ac28b66e1c30
Parents: a32d6d826570657f6ae3eba7b40de36274e3d084
Message:* update the permissions on IDF_Project::membershipsUpdated - listen to the same signal also for the initial setup, since the memberships haven't been added at the time the create signal is thrown * my array references goo was slightly stupid (the usage of foreach is of course hazardous in cases like this) * always insert a trailing new line in write-permissions and skip read-in newlines from being processed

Changes:

File differences

src/IDF/Plugin/SyncMonotone.php
3737
3838
3939
40
41
42
4043
4144
4245
......
6265
6366
6467
65
66
68
69
6770
6871
6972
......
262265
263266
264267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
265286
266
267
268
269
270287
271288
272289
......
466483
467484
468485
469
470
486
487
471488
472489
473
490
474491
475492
476493
......
510527
511528
512529
513
530
514531
515532
516533
517534
518
535
519536
520537
521538
......
572589
573590
574591
575
592
576593
577594
578595
......
588605
589606
590607
591
592
593
594
595
608
609
610
611
612
596613
597614
598
599615
600616
601617
......
610626
611627
612628
613
614
629
630
615631
616632
633
634
617635
618636
619
620637
621638
622
639
623640
624641
625642
case 'IDF_Project::created':
$plug->processProjectCreate($params['project']);
break;
case 'IDF_Project::membershipsUpdated':
$plug->processMembershipsUpdated($params['project']);
break;
case 'IDF_Project::preDelete':
$plug->processProjectDelete($params['project']);
break;
* 4) write monotonerc
* 5) add the database as new local server in the usher configuration
* 6) reload the running usher instance so it acknowledges the new server
* 7) create read-/write-permissions for the project and add all public
* keys to the project
*
* The initial right setup happens in processMembershipsUpdated()
*
* @param IDF_Project
*/
// step 6) reload usher to pick up the new configuration
//
IDF_Scm_Monotone_Usher::reload();
}
/**
* Updates the read / write permissions for the monotone database
*
* @param IDF_Project
*/
public function processMembershipsUpdated($project)
{
$projecttempl = Pluf::f('mtn_repositories', false);
if ($projecttempl === false) {
throw new IDF_Scm_Exception(
'"mtn_repositories" must be defined in your configuration file.'
);
}
$shortname = $project->shortname;
$projectpath = sprintf($projecttempl, $shortname);
//
// step 7) add public monotone keys for the project to
// read-permissions, write-permissions and the database
//
$mtn = IDF_Scm_Monotone::factory($project);
$stdio = $mtn->getStdio();
}
$wildcard_section = null;
foreach ($parsed_read_perms as $stanzas) {
foreach ($stanzas as $stanza_line) {
for ($i=0; $i<count($parsed_read_perms); ++$i) {
foreach ($parsed_read_perms[$i] as $stanza_line) {
if ($stanza_line['key'] == 'pattern' &&
$stanza_line['values'][0] == '*') {
$wildcard_section =& $stanzas;
$wildcard_section =& $parsed_read_perms[$i];
break;
}
}
}
$write_perms = file_get_contents($projectpath.'/write-permissions');
$lines = preg_split("/(\n|\r\n)/", $write_perms);
$lines = preg_split("/(\n|\r\n)/", $write_perms, -1, PREG_SPLIT_NO_EMPTY);
if (!in_array('*', $lines) && !in_array($mtn_key_id, $lines)) {
$lines[] = $mtn_key_id;
}
if (file_put_contents($projectpath.'/write-permissions',
implode("\n", $lines), LOCK_EX) === false) {
implode("\n", $lines) . "\n", LOCK_EX) === false) {
throw new IDF_Scm_Exception(sprintf(
__('Could not write write-permissions file for project "%s"'),
$shortname
// pattern "*"
// allow "*"
// which is the default for non-private projects
if ($project->private === true) {
if ($project->private) {
$read_perms = file_get_contents($projectpath.'/read-permissions');
$parsed_read_perms = array();
try {
// while we add new keys only to an existing wild-card entry
// we remove dropped keys from all sections since the key
// should be simply unavailable for all of them
foreach ($parsed_read_perms as $stanzas) {
for ($i=0; $i<count($stanzas); ) {
if ($stanzas[$i]['key'] == 'allow' &&
$stanzas[$i]['values'][0] == $mtn_key_id) {
unset($stanzas[$i]);
for ($h=0; $h<count($parsed_read_perms); ++$h) {
for ($i=0; $i<count($parsed_read_perms[$h]); ++$i) {
if ($parsed_read_perms[$h][$i]['key'] == 'allow' &&
$parsed_read_perms[$h][$i]['values'][0] == $mtn_key_id) {
unset($parsed_read_perms[$h][$i]);
continue;
}
++$i;
}
}
}
$write_perms = file_get_contents($projectpath.'/write-permissions');
$lines = preg_split("/(\n|\r\n)/", $write_perms);
for ($i=0; $i<count($lines); ) {
$lines = preg_split("/(\n|\r\n)/", $write_perms, -1, PREG_SPLIT_NO_EMPTY);
for ($i=0; $i<count($lines); ++$i) {
if ($lines[$i] == $mtn_key_id) {
unset($lines[$i]);
// the key should actually only exist once in the
// file, but we're paranoid
continue;
}
++$i;
}
if (file_put_contents($projectpath.'/write-permissions',
implode("\n", $lines), LOCK_EX) === false) {
implode("\n", $lines) . "\n", LOCK_EX) === false) {
throw new IDF_Scm_Exception(sprintf(
__('Could not write write-permissions file for project "%s"'),
$shortname
src/IDF/relations.php
8888
8989
9090
91
92
9193
9294
9395
# monotone synchronization
Pluf_Signal::connect('IDF_Project::created',
array('IDF_Plugin_SyncMonotone', 'entry'));
Pluf_Signal::connect('IDF_Project::membershipsUpdated',
array('IDF_Plugin_SyncMonotone', 'entry'));
Pluf_Signal::connect('IDF_Project::preDelete',
array('IDF_Plugin_SyncMonotone', 'entry'));
Pluf_Signal::connect('IDF_Key::postSave',

Archive Download the corresponding diff file

Page rendered in 0.08661s using 13 queries.