fix(vikon): skip existing files during FM sync, match original PHP diff behavior
Original vikon_core sync_root_dir.php only downloads files that are missing locally or have size 0. Added local file size check before downloading to avoid re-fetching 14GB+ of existing files.
This commit is contained in:
@@ -72,12 +72,23 @@ class SyncFilesAction
|
||||
$files = $response->json()['files'] ?? [];
|
||||
if (empty($files)) return 0;
|
||||
|
||||
$existingFiles = [];
|
||||
if (File::isDirectory($filesDir)) {
|
||||
foreach (File::files($filesDir) as $f) {
|
||||
$existingFiles[$f->getFilename()] = $f->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
$synced = 0;
|
||||
foreach ($files as $file) {
|
||||
$name = $file['n'] ?? null;
|
||||
$identity = $file['i'] ?? null;
|
||||
if (!$name || !$identity) continue;
|
||||
|
||||
if (isset($existingFiles[$name]) && $existingFiles[$name] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$content = $this->http->downloadWithToken(
|
||||
"sync/downloadFileBinaryForSync?identity={$identity}&moduleId={$moduleId}",
|
||||
@@ -107,12 +118,21 @@ class SyncFilesAction
|
||||
$targetDir = $filesDir . '/' . $dirId;
|
||||
File::makeDirectory($targetDir, 0755, true, true);
|
||||
|
||||
$existingFiles = [];
|
||||
foreach (File::files($targetDir) as $f) {
|
||||
$existingFiles[$f->getFilename()] = $f->getSize();
|
||||
}
|
||||
|
||||
$synced = 0;
|
||||
foreach ($files as $file) {
|
||||
$name = $file['n'] ?? null;
|
||||
$identity = $file['i'] ?? null;
|
||||
if (!$name || !$identity) continue;
|
||||
|
||||
if (isset($existingFiles[$name]) && $existingFiles[$name] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$content = $this->http->downloadWithToken(
|
||||
"sync/downloadFileBinaryForSync?identity={$identity}&moduleId={$moduleId}",
|
||||
|
||||
@@ -100,12 +100,23 @@ class UpdateCoreAction
|
||||
$files = $response->json()['files'] ?? [];
|
||||
if (empty($files)) return 0;
|
||||
|
||||
$existingFiles = [];
|
||||
if (File::isDirectory($filesDir)) {
|
||||
foreach (File::files($filesDir) as $f) {
|
||||
$existingFiles[$f->getFilename()] = $f->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
$synced = 0;
|
||||
foreach ($files as $file) {
|
||||
$name = $file['n'] ?? null;
|
||||
$identity = $file['i'] ?? null;
|
||||
if (!$name || !$identity) continue;
|
||||
|
||||
if (isset($existingFiles[$name]) && $existingFiles[$name] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$content = $this->http->downloadWithToken(
|
||||
"sync/downloadFileBinaryForSync?identity={$identity}&moduleId={$moduleId}",
|
||||
@@ -135,12 +146,21 @@ class UpdateCoreAction
|
||||
$targetDir = $filesDir . '/' . $dirId;
|
||||
File::makeDirectory($targetDir, 0755, true, true);
|
||||
|
||||
$existingFiles = [];
|
||||
foreach (File::files($targetDir) as $f) {
|
||||
$existingFiles[$f->getFilename()] = $f->getSize();
|
||||
}
|
||||
|
||||
$synced = 0;
|
||||
foreach ($files as $file) {
|
||||
$name = $file['n'] ?? null;
|
||||
$identity = $file['i'] ?? null;
|
||||
if (!$name || !$identity) continue;
|
||||
|
||||
if (isset($existingFiles[$name]) && $existingFiles[$name] > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$content = $this->http->downloadWithToken(
|
||||
"sync/downloadFileBinaryForSync?identity={$identity}&moduleId={$moduleId}",
|
||||
|
||||
Reference in New Issue
Block a user