diff --git a/classes/storage/StorageFilesystem.class.php b/classes/storage/StorageFilesystem.class.php index 5755025a0..a6df44735 100644 --- a/classes/storage/StorageFilesystem.class.php +++ b/classes/storage/StorageFilesystem.class.php @@ -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 { @@ -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; @@ -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"); diff --git a/classes/utils/Utilities.class.php b/classes/utils/Utilities.class.php index 0e80a8e07..e168d03cd 100644 --- a/classes/utils/Utilities.class.php +++ b/classes/utils/Utilities.class.php @@ -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 * @@ -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] - )); -*/ } /**