MCPcopy Create free account
hub / github.com/error311/FileRise / getUniqueFileNameForAdapter

Method getUniqueFileNameForAdapter

src/FileRise/Domain/FileModel.php:382–399  ·  view source on GitHub ↗
(StorageAdapterInterface $storage, string $destDir, string $fileName)

Source from the content-addressed store, hash-verified

380 }
381
382 private static function getUniqueFileNameForAdapter(StorageAdapterInterface $storage, string $destDir, string $fileName): string
383 {
384 $fullPath = $destDir . $fileName;
385 clearstatcache(true, $fullPath);
386 if ($storage->stat($fullPath) === null) {
387 return $fileName;
388 }
389 $basename = pathinfo($fileName, PATHINFO_FILENAME);
390 $extension = pathinfo($fileName, PATHINFO_EXTENSION);
391 $counter = 1;
392 do {
393 $newName = $basename . " (" . $counter . ")" . ($extension ? "." . $extension : "");
394 $newFullPath = $destDir . $newName;
395 clearstatcache(true, $newFullPath);
396 $counter++;
397 } while ($storage->stat($destDir . $newName) !== null);
398 return $newName;
399 }
400
401 private static function adapterErrorDetail(StorageAdapterInterface $storage): string
402 {

Callers 3

getUniqueFileNameMethod · 0.95

Calls 1

statMethod · 0.45

Tested by

no test coverage detected