Skip to content

Commit

Permalink
FTPAdapter: Use more precise time for 'timestampsOnUnixListings' option
Browse files Browse the repository at this point in the history
  • Loading branch information
themark147 committed Jan 24, 2025
1 parent 704c10b commit 27a9f23
Showing 1 changed file with 8 additions and 14 deletions.
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

0 comments on commit 27a9f23

Please sign in to comment.