From c751173c52994e8ed419c7825d5e3182902ab861 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 2 May 2024 13:10:30 -0700 Subject: [PATCH] Fix public_data:commit's symlinking on some platforms Huh, curious, I think what I'm seeing is: on my development machine, `File.exist?` returns true for symlinks, but, on our production machine, `File.exist?` returns false for symlinks. I imagine this is a difference in the implementation of the underlying system calls? Curious! This new check should work more reliably across platforms. I considered checking both `exists?` and `symlink?`, but decided that, in the unexpected case that `latest.sql.gz` exists but is an actual file instead of a symlink like we expect, it's probably best to avoid overwriting it anyway, and a crash on the `symlink` attempt is a reasonable way to do that. --- lib/tasks/public_data.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/public_data.rake b/lib/tasks/public_data.rake index 6ae2541f..4737a3d0 100644 --- a/lib/tasks/public_data.rake +++ b/lib/tasks/public_data.rake @@ -56,7 +56,7 @@ namespace :public_data do # Link this latest dump as `latest.sql.gz`. latest_path = Rails.configuration.public_data_root / "latest.sql.gz" - File.unlink(latest_path) if File.exist?(latest_path) + File.unlink(latest_path) if File.symlink?(latest_path) File.symlink(dest_path, latest_path) puts "Linked dump to #{latest_path}"