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

FTPAdapter: Use more precise time for 'timestampsOnUnixListings' option #1847

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function listContents(string $path, bool $deep): iterable
yield from $this->listDirectoryContentsRecursive($path);
} else {
$location = $this->prefixer()->prefixPath($path);
$options = $deep ? '-alnR' : '-aln';
$options = $deep ? '-alnRT' : '-alnT';
$listing = $this->ftpRawlist($options, $location);
yield from $this->normalizeListing($listing, $path);
}
Expand Down Expand Up @@ -426,20 +426,21 @@ private function normalizeWindowsObject(string $item, string $base): StorageAttr
private function normalizeUnixObject(string $item, string $base): StorageAttributes
{
$item = preg_replace('#\s+#', ' ', trim($item), 7);
$parts = explode(' ', $item, 9);
$parts = explode(' ', $item, 10);

if (count($parts) !== 9) {
if (count($parts) !== 10) {
throw new InvalidListResponseReceived("Metadata can't be parsed from item '$item' , not enough parts.");
}

[$permissions, /* $number */, /* $owner */, /* $group */, $size, $month, $day, $timeOrYear, $name] = $parts;
[$permissions, /* $number */, /* $owner */, /* $group */, $size, $month, $day, $time, $year, $name] = $parts;
$isDirectory = $this->listingItemIsDirectory($permissions);
$permissions = $this->normalizePermissions($permissions);
$path = $base === '' ? $name : rtrim($base, '/') . '/' . $name;
$lastModified = $this->connectionOptions->timestampsOnUnixListingsEnabled() ? $this->normalizeUnixTimestamp(
$month,
$day,
$timeOrYear
$time,
$year
) : null;

if ($isDirectory) {
Expand All @@ -460,16 +461,9 @@ private function listingItemIsDirectory(string $permissions): bool
return str_starts_with($permissions, 'd');
}

private function normalizeUnixTimestamp(string $month, string $day, string $timeOrYear): int
private function normalizeUnixTimestamp(string $month, string $day, string $time, string $year): int
{
if (is_numeric($timeOrYear)) {
$year = $timeOrYear;
$hour = '00';
$minute = '00';
} else {
$year = date('Y');
[$hour, $minute] = explode(':', $timeOrYear);
}
[$hour, $minute, $seconds] = explode(':', $time);

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

Expand Down
Loading