Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use uuidv4 for all uuids again for now. update to filesystem daily buckets to work with uuidv4 #1812

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 27 additions & 4 deletions classes/storage/StorageFilesystem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ public static function buildPath(File $file, $fullPath = true )

$perDayBuckets = $file->transfer->storage_filesystem_per_day_buckets;
$perHourBuckets = $file->transfer->storage_filesystem_per_hour_buckets;
Logger::error("AAA daily $perDayBuckets hourly $perHourBuckets ");

if( $perDayBuckets || $perHourBuckets ) {
try {
Expand Down Expand Up @@ -391,7 +390,32 @@ public static function buildPath(File $file, $fullPath = true )
if (substr($path, -1) != '/') {
$path .= '/';
}
}
} else {
$tt = $file->transfer->created;
$startOfDay = $tt - ($tt % (60*60*24));
$startOfHour = $tt - ($tt % (60*60 ));
if( $perDayBuckets ) {
$subpath = "" . $startOfDay;
}
if( $perHourBuckets ) {
if( $subpath != "" ) {
$subpath .= "/";
}
$subpath .= "" . $startOfHour;
}

$now = time();
$npath = $path . $subpath . "/";
// only make the directories if it is recent enough
if( $tt > $now - (Config::get("storage_filesystem_per_day_max_age_to_create_directory")*24*3600) ) {
$path = StorageFilesystem::ensurePath( $path, $subpath );
} else {
$path = $npath;
}
if (substr($path, -1) != '/') {
$path .= '/';
}
}
} catch (Exception $e) {
Logger::error("Issue with per day buckets and UUID");
return $path;
Expand Down Expand Up @@ -636,8 +660,7 @@ public static function deleteEmptyBucketDirectories()

if( $perDayBuckets || $perHourBuckets ) {
try {
$uuid = Ramsey\Uuid\Uuid::uuid7();
$tt = $uuid->getDateTime()->getTimestamp();
$tt = time();
$startOfDay = $tt - ($tt % (60*60*24));

$daysback = Config::get("storage_filesystem_per_day_min_days_to_clean_empty_directories");
Expand Down
26 changes: 4 additions & 22 deletions classes/utils/Utilities.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ class Utilities
private static $security_token = null;

/**
* Generate a unique ID to be used as token
* Generate a unique ID to be used as token.
* All generated UUID are version 4.
*
* @param bool $timestamped requests a timestamped (uuidv7) or non-timestamped (uuidv4) uid
* @param bool $timestamped in the future requests a timestamped (uuidv7) or non-timestamped (uuidv4) uid
* @param callable $unicity_checker callback used to check for uid unicity (takes uid as sole argument, returns bool telling if uid is unique), null if check not needed
* @param int $max_tries maximum number of tries before giving up and throwing
*
Expand Down Expand Up @@ -87,27 +88,8 @@ public static function generateUID($timestamped = false, $unicity_checker = null
return $uid;
}

$uuid = $timestamped ? Ramsey\Uuid\Uuid::uuid7() : Ramsey\Uuid\Uuid::uuid4();
$uuid = Ramsey\Uuid\Uuid::uuid4();
return $uuid->toString();
/*
// Generate 16 bytes of random data (128 bits)
$bytes = random_bytes(16);
// Set bits required for a valid UUIDv4
$bytes[8] = chr((ord($bytes[8]) & 0x3F) | 0x80); // Eat 2 bits of entropy
$bytes[6] = chr((ord($bytes[6]) & 0x4F) | 0x40); // Eat 4 bits of entropy
// $bytes has now 122 bits of entropy

// Convert bytes to hex and split in 4-char strings (hex, so 2 bytes per string)
$parts = str_split(bin2hex($bytes), 4);
// Add dashes where UUIDs should have dashes
return implode('-', array(
$parts[0] . $parts[1],
$parts[2],
$parts[3],
$parts[4],
$parts[5] . $parts[6] . $parts[7]
));
*/
}

/**
Expand Down