Skip to content

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.rb
index 9b7148efc8c..6d4e733a359 100644
--- a/lib/file_store/local_store.rb
+++ b/lib/file_store/local_store.rb
@@ -17,6 +17,7 @@ module FileStore
dir = Pathname.new(destination).dirname
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
FileUtils.move(source, destination, force: true)
+ FileUtils.touch(destination)
end
def has_been_uploaded?(url)
diff --git a/spec/components/file_store/local_store_spec.rb b/spec/components/file_store/local_store_spec.rb
index 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 do
let(:optimized_image) { Fabricate(:optimized_image) }
- describe ".store_upload" do
+ describe "#store_upload" do
it "returns a relative url" do
store.expects(:copy_file)
@@ -19,7 +19,7 @@ describe FileStore::LocalStore do
end
- describe ".store_optimized_image" do
+ describe "#store_optimized_image" do
it "returns a relative url" do
store.expects(:copy_file)
@@ -28,7 +28,7 @@ describe FileStore::LocalStore do
end
- describe ".remove_upload" do
+ describe "#remove_upload" do
it "does not delete non uploaded" do
FileUtils.expects(:mkdir_p).never
@@ -36,26 +36,58 @@ describe FileStore::LocalStore do
end
it "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
+ end
end
end
- describe ".remove_optimized_image" do
- let(:optimized_image) { Fabricate(:optimized_image, url: "/uploads/default/_optimized/42/253dc8edf9d4ada1.png") }
-
+ describe "#remove_optimized_image" do
it "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
+ end
end
end
- describe ".has_been_uploaded?" do
+ describe "#has_been_uploaded?" do
it "identifies relatives urls" do
expect(store.has_been_uploaded?("/uploads/default/42/0123456789ABCDEF.jpg")).to eq(true)
@@ -85,7 +117,7 @@ describe FileStore::LocalStore do
Discourse.stubs(:base_uri).returns("/forum")
end
- describe ".absolute_base_url" do
+ describe "#absolute_base_url" do
it "is present" do
expect(store.absolute_base_url).to eq("http://test.localhost/uploads/default")
@@ -98,7 +130,7 @@ describe FileStore::LocalStore do
end
- describe ".relative_base_url" do
+ describe "#relative_base_url" do
it "is present" do
expect(store.relative_base_url).to eq("/uploads/default")
diff --git a/spec/fixtures/images/smallest.png b/spec/fixtures/images/smallest.png
new file mode 100644
index 00000000000..91a99b94e23
Binary files /dev/null and b/spec/fixtures/images/smallest.png differ