Skip to content

Commit

Permalink
Merge pull request #1747 from tinect/fix/ensurePrefixForFtp
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge authored Feb 4, 2024
2 parents 131782c + 67086c1 commit c1faa2f
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private function fetchMetadata(string $path, string $type): FileAttributes

$object = @ftp_raw($this->connection(), 'STAT ' . $location);

if (empty($object) || count($object) < 3 || substr($object[1], 0, 5) === "ftpd:") {
if (empty($object) || count($object) < 3 || str_starts_with($object[1], "ftpd:")) {
throw UnableToRetrieveMetadata::create($path, $type, error_get_last()['message'] ?? '');
}

Expand Down Expand Up @@ -450,7 +450,7 @@ private function normalizeUnixObject(string $item, string $base): StorageAttribu

private function listingItemIsDirectory(string $permissions): bool
{
return substr($permissions, 0, 1) === 'd';
return str_starts_with($permissions, 'd');
}

private function normalizeUnixTimestamp(string $month, string $day, string $timeOrYear): int
Expand All @@ -459,14 +459,12 @@ private function normalizeUnixTimestamp(string $month, string $day, string $time
$year = $timeOrYear;
$hour = '00';
$minute = '00';
$seconds = '00';
} else {
$year = date('Y');
[$hour, $minute] = explode(':', $timeOrYear);
$seconds = '00';
}

$dateTime = DateTime::createFromFormat('Y-M-j-G:i:s', "{$year}-{$month}-{$day}-{$hour}:{$minute}:{$seconds}");
$dateTime = DateTime::createFromFormat('Y-M-j-G:i:s', "$year-$month-$day-$hour:$minute:00");

return $dateTime->getTimestamp();
}
Expand All @@ -484,19 +482,14 @@ private function normalizePermissions(string $permissions): int
$parts = str_split($permissions, 3);

// convert the groups
$mapper = function ($part) {
$mapper = static function ($part) {
return array_sum(str_split($part));
};

// converts to decimal number
return octdec(implode('', array_map($mapper, $parts)));
}

/**
* @inheritdoc
*
* @param string $directory
*/
private function listDirectoryContentsRecursive(string $directory): Generator
{
$location = $this->prefixer()->prefixPath($directory);
Expand Down Expand Up @@ -583,9 +576,6 @@ private function ensureParentDirectoryExists(string $path, ?string $visibility):
$this->ensureDirectoryExists($dirname, $visibility);
}

/**
* @param string $dirname
*/
private function ensureDirectoryExists(string $dirname, ?string $visibility): void
{
$connection = $this->connection();
Expand Down Expand Up @@ -634,9 +624,10 @@ private function hasFtpConnection(): bool

public function directoryExists(string $path): bool
{
$location = $this->prefixer()->prefixPath($path);
$connection = $this->connection();

return @ftp_chdir($connection, $path) === true;
return @ftp_chdir($connection, $location) === true;
}

/**
Expand Down

0 comments on commit c1faa2f

Please sign in to comment.