A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix: no file validation exists for sync files
aminnausind6d9c66fbc61
diff --git a/app/Jobs/SyncFiles.php b/app/Jobs/SyncFiles.phpindex 3ba15d88..6518f7fc 100755--- a/app/Jobs/SyncFiles.php+++ b/app/Jobs/SyncFiles.php@@ -67,16 +67,22 @@ class SyncFiles extends ManagedSubTask {$folders = $subDirectories['folderChanges'];$videos = $files['videoChanges'];- Storage::put('categories.json', json_encode($directories['data'], JSON_UNESCAPED_SLASHES));- Storage::put('folders.json', json_encode($subDirectories['data'], JSON_UNESCAPED_SLASHES));- Storage::put('videos.json', json_encode($files['data'], JSON_UNESCAPED_SLASHES));+ $outputFiles = [+ 'categories.json' => json_encode($directories['data'], JSON_UNESCAPED_SLASHES),+ 'folders.json' => json_encode($subDirectories['data'], JSON_UNESCAPED_SLASHES),+ 'videos.json' => json_encode($files['data'], JSON_UNESCAPED_SLASHES),+ ];$data = ['categories' => $categories, 'folders' => $folders, 'videos' => $videos];$dataCache = Storage::json('dataCache.json') ?? [];$dataCache[date('Y-m-d-h:i:sa')] = ['job' => 'sync', 'data' => $data];- Storage::put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));+ $outputFiles['dataCache.json'] = json_encode($dataCache, JSON_UNESCAPED_SLASHES);++ foreach ($outputFiles as $path => $data) {+ $this->safePut($path, $data);+ }if (! $this->batch()) {dump('Categories | Folders | Videos | Data | dataCache', $directories, $subDirectories, $files, $data, $dataCache);@@ -230,4 +236,24 @@ class SyncFiles extends ManagedSubTask {return ['videoChanges' => $changes, 'data' => $data, 'cost' => $cost, 'updatedFolderStructure' => $foldersCopy];}++ /**+ * Write to storage with error checking+ *+ * @throws \RuntimeException+ */+ private function safePut(string $path, $contents): bool {+ if (!Storage::put($path, $contents)) {+ throw new \RuntimeException("Failed to write file: {$path}");+ }++ if (config('app.debug')) {+ $written = Storage::get($path);+ if ($written !== $contents) {+ throw new \RuntimeException("Write verification failed for: {$path}");+ }+ }++ return true;+ }}