A platform for community discussion. Free, open, simple.
FIX: Moving upload to tombstone should update modification time.
Guo Xiang Tance6a0a5e9e33
diff --git a/lib/file_store/local_store.rb b/lib/file_store/local_store.rbindex 9b7148efc8c..6d4e733a359 100644--- a/lib/file_store/local_store.rb+++ b/lib/file_store/local_store.rb@@ -17,6 +17,7 @@ module FileStoredir = Pathname.new(destination).dirnameFileUtils.mkdir_p(dir) unless Dir.exists?(dir)FileUtils.move(source, destination, force: true)+ FileUtils.touch(destination)enddef has_been_uploaded?(url)diff --git a/spec/components/file_store/local_store_spec.rb b/spec/components/file_store/local_store_spec.rbindex b9696ed0912..45b91b80f9f 100644--- a/spec/components/file_store/local_store_spec.rb+++ b/spec/components/file_store/local_store_spec.rb@@ -10,7 +10,7 @@ describe FileStore::LocalStore dolet(:optimized_image) { Fabricate(:optimized_image) }- describe ".store_upload" do+ describe "#store_upload" doit "returns a relative url" dostore.expects(:copy_file)@@ -19,7 +19,7 @@ describe FileStore::LocalStore doend- describe ".store_optimized_image" do+ describe "#store_optimized_image" doit "returns a relative url" dostore.expects(:copy_file)@@ -28,7 +28,7 @@ describe FileStore::LocalStore doend- describe ".remove_upload" do+ describe "#remove_upload" doit "does not delete non uploaded" doFileUtils.expects(:mkdir_p).never@@ -36,26 +36,58 @@ describe FileStore::LocalStore doendit "moves the file to the tombstone" do- filename = File.basename(store.path_for(upload))- store.remove_upload(upload)- expect(File.exist?(store.tombstone_dir + "/" + filename))+ begin+ upload = UploadCreator.new(+ file_from_fixtures("smallest.png"),+ "smallest.png"+ ).create_for(Fabricate(:user).id)++ path = store.path_for(upload)+ mtime = File.mtime(path)++ sleep 0.01 # Delay a little for mtime to be updated+ store.remove_upload(upload)+ tombstone_path = path.sub("/uploads/", "/uploads/tombstone/")++ expect(File.exist?(tombstone_path)).to eq(true)+ expect(File.mtime(tombstone_path)).to_not eq(mtime)+ ensure+ [path, tombstone_path].each do |file_path|+ File.delete(file_path) if File.exist?(file_path)+ end+ endendend- describe ".remove_optimized_image" do- let(:optimized_image) { Fabricate(:optimized_image, url: "/uploads/default/_optimized/42/253dc8edf9d4ada1.png") }-+ describe "#remove_optimized_image" doit "moves the file to the tombstone" do- FileUtils.expects(:mkdir_p)- FileUtils.expects(:move)- File.expects(:exists?).returns(true)- store.remove_optimized_image(optimized_image)+ begin+ upload = UploadCreator.new(+ file_from_fixtures("smallest.png"),+ "smallest.png"+ ).create_for(Fabricate(:user).id)++ upload.create_thumbnail!(1, 1)+ upload.reload++ optimized_image = upload.thumbnail(1, 1)+ path = store.path_for(optimized_image)++ store.remove_optimized_image(optimized_image)+ tombstone_path = path.sub("/uploads/", "/uploads/tombstone/")++ expect(File.exist?(tombstone_path)).to eq(true)+ ensure+ [path, tombstone_path].each do |file_path|+ File.delete(file_path) if File.exist?(file_path)+ end+ endendend- describe ".has_been_uploaded?" do+ describe "#has_been_uploaded?" doit "identifies relatives urls" doexpect(store.has_been_uploaded?("/uploads/default/42/0123456789ABCDEF.jpg")).to eq(true)@@ -85,7 +117,7 @@ describe FileStore::LocalStore doDiscourse.stubs(:base_uri).returns("/forum")end- describe ".absolute_base_url" do+ describe "#absolute_base_url" doit "is present" doexpect(store.absolute_base_url).to eq("http://test.localhost/uploads/default")@@ -98,7 +130,7 @@ describe FileStore::LocalStore doend- describe ".relative_base_url" do+ describe "#relative_base_url" doit "is present" doexpect(store.relative_base_url).to eq("/uploads/default")diff --git a/spec/fixtures/images/smallest.png b/spec/fixtures/images/smallest.pngnew file mode 100644index 00000000000..91a99b94e23Binary files /dev/null and b/spec/fixtures/images/smallest.png differ