Skip to content

Commit a132c80

Browse files
GlobalIdGenerator: include user id in file prefix
On systems where multiple users run MediaWiki installations (such as shared hosting), it's needed to make the file prefix for the GlobalIdGenerator unique per user, to prevent potential permission errors due to colliding temporary files. This commit includes the value of `getmyuid()` in the file prefix, as proposed in the comments of task T268420. Bug: T268420 Change-Id: I1abbce3e2394d3aa54cb058b96d9bf85aeec6b44
1 parent f0a859f commit a132c80

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

includes/libs/uuid/GlobalIdGenerator.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class GlobalIdGenerator {
3737

3838
/** @var string Temporary directory */
3939
protected $tmpDir;
40+
/** @var string
41+
* File prefix containing user ID to prevent collisions
42+
* if multiple users run MediaWiki (T268420)
43+
*/
44+
protected $uniqueFilePrefix;
4045
/** @var string Local file path */
4146
protected $nodeIdFile;
4247
/** @var string Node ID in binary (32 bits) */
@@ -92,12 +97,13 @@ public function __construct( $tempDirectory, $shellCallback ) {
9297
throw new InvalidArgumentException( "No temp directory provided" );
9398
}
9499
$this->tmpDir = $tempDirectory;
95-
$this->nodeIdFile = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-nodeid';
100+
$this->uniqueFilePrefix = self::FILE_PREFIX . getmyuid();
101+
$this->nodeIdFile = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-nodeid';
96102
// If different processes run as different users, they may have different temp dirs.
97103
// This is dealt with by initializing the clock sequence number and counters randomly.
98-
$this->lockFile88 = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-88';
99-
$this->lockFile128 = $tempDirectory . '/' . self::FILE_PREFIX . '-UID-128';
100-
$this->lockFileUUID = $tempDirectory . '/' . self::FILE_PREFIX . '-UUID-128';
104+
$this->lockFile88 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-88';
105+
$this->lockFile128 = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UID-128';
106+
$this->lockFileUUID = $tempDirectory . '/' . $this->uniqueFilePrefix . '-UUID-128';
101107

102108
$this->shellCallback = $shellCallback;
103109
}
@@ -373,7 +379,7 @@ protected function getSequentialPerNodeIDs( $bucket, $bits, $count, $flags ) {
373379
throw new RuntimeException( "Requested bit size ($bits) is out of range." );
374380
}
375381

376-
$path = $this->tmpDir . '/' . self::FILE_PREFIX . '-' . rawurlencode( $bucket ) . '-48';
382+
$path = $this->tmpDir . '/' . $this->uniqueFilePrefix . '-' . rawurlencode( $bucket ) . '-48';
377383
// Get the UID lock file handle
378384
if ( isset( $this->fileHandles[$path] ) ) {
379385
$handle = $this->fileHandles[$path];

0 commit comments

Comments
 (0)