File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -166,12 +166,18 @@ public function store(Request $request)
166166
167167 $ newPath = storage_path ('docs/ ' . $ doc ->id );
168168
169+ $ deduplicated = false ;
169170 if ($ existingDocument !== null ) {
170171 // Reuse existing file - create hard link
171172 $ existingPath = storage_path ('docs/ ' . $ existingDocument ->id );
172173
173174 if (file_exists ($ existingPath )) {
174- link ($ existingPath , $ newPath );
175+ if (link ($ existingPath , $ newPath )) {
176+ $ deduplicated = true ;
177+ } else {
178+ // Fallback: hard-link failed (e.g., different filesystem)
179+ $ file ->move (storage_path ('docs ' ), (string ) $ doc ->id );
180+ }
175181 } else {
176182 // Fallback: if existing file is missing, store the uploaded file
177183 $ file ->move (storage_path ('docs ' ), (string ) $ doc ->id );
@@ -186,7 +192,7 @@ public function store(Request $request)
186192 [
187193 'success ' => $ doc ->filename ,
188194 'id ' => $ doc ->id ,
189- 'deduplicated ' => $ existingDocument !== null ,
195+ 'deduplicated ' => $ deduplicated ,
190196 ]
191197 );
192198 }
You can’t perform that action at this time.
0 commit comments