about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-03-11 11:23:50 +0100
committerThibaut Girka <thib@sitedethib.com>2019-03-11 11:23:50 +0100
commit89bee860cdae399b796814f80a48eafa8b838d92 (patch)
tree7f31aaa85f78b170f22cadd8c53fca8d09f8e795 /app/controllers
parent3cef04610cd809c7bd01adc00d34fb3d25261a16 (diff)
parent13a7f05030cdcbab24aeb25944a9a430238dbff1 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/services/post_status_service.rb
  Small conflict due to handling of instance-local toots.
  A subsequent change is required to ensure instance-local polls are not leaked
  through Update.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/settings/exports_controller.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/app/controllers/settings/exports_controller.rb b/app/controllers/settings/exports_controller.rb
index cf8745576..7f76668d5 100644
--- a/app/controllers/settings/exports_controller.rb
+++ b/app/controllers/settings/exports_controller.rb
@@ -9,11 +9,25 @@ class Settings::ExportsController < Settings::BaseController
   end
 
   def create
-    authorize :backup, :create?
+    raise Mastodon::NotPermittedError unless user_signed_in?
+
+    backup = nil
+
+    RedisLock.acquire(lock_options) do |lock|
+      if lock.acquired?
+        authorize :backup, :create?
+        backup = current_user.backups.create!
+      else
+        raise Mastodon::RaceConditionError
+      end
+    end
 
-    backup = current_user.backups.create!
     BackupWorker.perform_async(backup.id)
 
     redirect_to settings_export_path
   end
+
+  def lock_options
+    { redis: Redis.current, key: "backup:#{current_user.id}" }
+  end
 end