From d0b22a371bdd4e8f09df8ba63c6206208c244c86 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sun, 30 Jun 2019 21:26:41 +0000
Subject: [PATCH] Use Composer's PSR-0 autoloader
---
lib/fetch.php | 36 +++++++++---------------------------
1 files changed, 9 insertions(+), 27 deletions(-)
diff --git a/lib/fetch.php b/lib/fetch.php
index 9c54486..3c3ca75 100644
--- a/lib/fetch.php
+++ b/lib/fetch.php
@@ -30,41 +30,23 @@
$localSize = filesize($file);
}
- $ftp = ftp_connect($url['host'], $url['port'], 10);
- if($ftp === FALSE) {
- throw new Exception('FTP connection failed');
- }
- if(!ftp_login($ftp, $url['user'], $url['pass'])) {
- throw new Exception('FTP login failed');
- }
- if(!ftp_pasv($ftp, TRUE)) {
- throw new Exception('Passive FTP request failed');
- }
- $remoteSize = ftp_size($ftp, $url['path']);
- if($remoteSize < 0) {
- throw new Exception('FTP file size fetch failed');
- }
- $remoteTime = ftp_mdtm($ftp, $url['path']);
- if($remoteTime < 0) {
- throw new Exception('FTP modification time fetch failed');
- }
+ $ftp = FtpConnection::create($url['host'], $url['port'], $url['user'], $url['pass']);
+ $remoteSize = $ftp->size($url['path']);
+ $remoteTime = $ftp->mdtm($url['path']);
$updated = FALSE;
- if($localSize != $remoteSize || $localTime < $remoteTime) {
+ if($localTime < $remoteTime || ($localTime == $remoteTime && $localSize != $remoteSize)) {
if(file_exists($file.'.tmp')) {
unlink($file.'.tmp');
}
- if(ftp_get($ftp, $file.'.tmp', $url['path'], FTP_BINARY)) {
- touch($file.'.tmp', $remoteTime);
- if(!rename($file.'.tmp', $file)) {
- throw new Exception('Temporary file rename failed');
- }
- $updated = TRUE;
+ $ftp->get($file.'.tmp', $url['path'], FTP_BINARY);
+ touch($file.'.tmp', $remoteTime);
+ if(!rename($file.'.tmp', $file)) {
+ throw new Exception('Temporary file rename failed');
}
+ $updated = TRUE;
}
-
- ftp_close($ftp);
return $updated;
}
--
Gitblit v1.9.1