From d782a261e2b6466348a6dfc040fac24a3937e174 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 15 Feb 2015 16:26:00 +0100 Subject: s/file/add_file: make file move atomic Signed-off-by: Florian Pritz --- application/service/files.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'application/service') diff --git a/application/service/files.php b/application/service/files.php index e31efacc1..a2aa83c3b 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -78,9 +78,11 @@ class files { file_exists($dir) || mkdir ($dir); $new_path = $CI->mfile->file($hash); - // TODO: make this operation atomic (move to temp name, then to final) - // the source can be a different file system so this might do a copy - move_uploaded_file($file, $new_path); + $dest = new \service\storage($new_path); + $tmpfile = $dest->begin(); + move_uploaded_file($file, $tmpfile); + $dest->commit(); + $CI->mfile->add_file($hash, $id, $filename); } -- cgit v1.2.3-24-g4f1b