Skip to content

Commit ef6239c

Browse files
committed
Only pass in original content if using diffcrypt format
This fixes an issue where converting rails native format for the first time would break
1 parent 4b58c59 commit ef6239c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/diffcrypt/rails/encrypted_configuration.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
2929
@active_support_encryptor = ActiveSupport::MessageEncryptor.new([key].pack('H*'), cipher: Encryptor::CIPHER)
3030
end
3131

32+
# Determines if file is using the diffable format, or still
33+
# encrypted using default rails credentials format
34+
# @return [Boolean]
35+
def content_path_diffable?
36+
content_path.binread.index('---')&.zero?
37+
end
38+
3239
# Allow a config to be started without a file present
3340
# @return [String] Returns decryped content or a blank string
3441
def read
@@ -72,7 +79,7 @@ def writing(contents)
7279

7380
updated_contents = tmp_path.binread
7481

75-
write(updated_contents, content_path.binread)
82+
write(updated_contents, content_path_diffable? && content_path.binread)
7683
ensure
7784
FileUtils.rm(tmp_path) if tmp_path&.exist?
7885
end

0 commit comments

Comments
 (0)