FIX: Moving upload to tombstone should update modification time.
A upload created a long time ago will be nuked from the tombstone immediately if it gets deleted.
This commit is contained in:
parent
f2fbf1fdb0
commit
ce6a0a5e9e
|
@ -17,6 +17,7 @@ module FileStore
|
||||||
dir = Pathname.new(destination).dirname
|
dir = Pathname.new(destination).dirname
|
||||||
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
|
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
|
||||||
FileUtils.move(source, destination, force: true)
|
FileUtils.move(source, destination, force: true)
|
||||||
|
FileUtils.touch(destination)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_been_uploaded?(url)
|
def has_been_uploaded?(url)
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe FileStore::LocalStore do
|
||||||
|
|
||||||
let(:optimized_image) { Fabricate(:optimized_image) }
|
let(:optimized_image) { Fabricate(:optimized_image) }
|
||||||
|
|
||||||
describe ".store_upload" do
|
describe "#store_upload" do
|
||||||
|
|
||||||
it "returns a relative url" do
|
it "returns a relative url" do
|
||||||
store.expects(:copy_file)
|
store.expects(:copy_file)
|
||||||
|
@ -19,7 +19,7 @@ describe FileStore::LocalStore do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".store_optimized_image" do
|
describe "#store_optimized_image" do
|
||||||
|
|
||||||
it "returns a relative url" do
|
it "returns a relative url" do
|
||||||
store.expects(:copy_file)
|
store.expects(:copy_file)
|
||||||
|
@ -28,7 +28,7 @@ describe FileStore::LocalStore do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".remove_upload" do
|
describe "#remove_upload" do
|
||||||
|
|
||||||
it "does not delete non uploaded" do
|
it "does not delete non uploaded" do
|
||||||
FileUtils.expects(:mkdir_p).never
|
FileUtils.expects(:mkdir_p).never
|
||||||
|
@ -36,26 +36,58 @@ describe FileStore::LocalStore do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "moves the file to the tombstone" do
|
it "moves the file to the tombstone" do
|
||||||
filename = File.basename(store.path_for(upload))
|
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)
|
store.remove_upload(upload)
|
||||||
expect(File.exist?(store.tombstone_dir + "/" + filename))
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".remove_optimized_image" do
|
describe "#remove_optimized_image" do
|
||||||
let(:optimized_image) { Fabricate(:optimized_image, url: "/uploads/default/_optimized/42/253dc8edf9d4ada1.png") }
|
|
||||||
|
|
||||||
it "moves the file to the tombstone" do
|
it "moves the file to the tombstone" do
|
||||||
FileUtils.expects(:mkdir_p)
|
begin
|
||||||
FileUtils.expects(:move)
|
upload = UploadCreator.new(
|
||||||
File.expects(:exists?).returns(true)
|
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)
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".has_been_uploaded?" do
|
describe "#has_been_uploaded?" do
|
||||||
|
|
||||||
it "identifies relatives urls" do
|
it "identifies relatives urls" do
|
||||||
expect(store.has_been_uploaded?("/uploads/default/42/0123456789ABCDEF.jpg")).to eq(true)
|
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")
|
Discourse.stubs(:base_uri).returns("/forum")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".absolute_base_url" do
|
describe "#absolute_base_url" do
|
||||||
|
|
||||||
it "is present" do
|
it "is present" do
|
||||||
expect(store.absolute_base_url).to eq("http://test.localhost/uploads/default")
|
expect(store.absolute_base_url).to eq("http://test.localhost/uploads/default")
|
||||||
|
@ -98,7 +130,7 @@ describe FileStore::LocalStore do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".relative_base_url" do
|
describe "#relative_base_url" do
|
||||||
|
|
||||||
it "is present" do
|
it "is present" do
|
||||||
expect(store.relative_base_url).to eq("/uploads/default")
|
expect(store.relative_base_url).to eq("/uploads/default")
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 67 B |
Loading…
Reference in New Issue