DEV: Work around a Docker issue (#13368)

DEV: Work around a Docker issue (#13368)

Fixes our backend spec suite in GitHub Actions CI. For more information about the Docker issue see: Very specific set of circumstances leads to zero-byte (empty) file being created · Issue #1015 · docker/for-linux · GitHub

(It’s possible that error could also happen in dev/production, though thankfully that hasn’t happened yet afaik)

diff --git a/lib/freedom_patches/copy_file.rb b/lib/freedom_patches/copy_file.rb
new file mode 100644
index 0000000..3a411b8
--- /dev/null
+++ b/lib/freedom_patches/copy_file.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require "fileutils"
+
+# See: https://github.com/docker/for-linux/issues/1015
+
+module FileUtils
+  class Entry_
+    def copy_file(dest)
+      File.open(path()) do |s|
+        File.open(dest, "wb", s.stat.mode) do |f|
+          IO.copy_stream(s, f)
+          f.chmod(f.lstat.mode)
+        end
+      end
+    end
+  end
+end

GitHub sha: 091beaf4a22247f2a5adf243aa9c46a1c6dcade1

This commit appears in #13368 which was approved by davidtaylorhq. It was merged by CvX.