longleaf 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71c3c9e78a968f153c457d2a59ae17e8d45b4f6e905deeb787172844cee3733f
4
- data.tar.gz: d354dba30939cdf1917b09fa7fc874654135f311dd1d5c60453cb42fe2b2a736
3
+ metadata.gz: eb37785f1fd9fc03721f7cdc3946f648d3c1e126385677daba89fdcfb3c32330
4
+ data.tar.gz: a208d7c6c79440563950c6b64647637f75fa3687690ff496395cab5e524408f3
5
5
  SHA512:
6
- metadata.gz: af2433108df902de025137d67c4b3d089b8766f7856d10d5d93d6bd449b82227c7cf3e987e50199c83a0869056842cb34d55f710102fa8a654282170c215882a
7
- data.tar.gz: 93deda52a5f3de34ebc29baef3f531db099ea76521389dc223f33c2922da0e1fb81d775c8178370ade67ea397761553bf9ec34c03c12eec1e0a77d12174e07de
6
+ metadata.gz: 2d1df2dd6abad7c04af677ca571308b322368daeaa27ddde4bc48d2804819851b19e66ce6c66a01007a8439c7c6d6c5937de8c55813ee9af3f2b99a4486affa9
7
+ data.tar.gz: 2d2ba20c34cdf8abeeb163558b5eb5dec681fb03c17029e97ee3fa9f58ec36de00d9c1b8e8e5effbcf0dcd8ac8abb75866a8983efbd68bff8669f9a9d7a046ef
@@ -105,6 +105,7 @@ module Longleaf
105
105
  original_file.flock(File::LOCK_EX)
106
106
 
107
107
  base_name = File.basename(file_path)
108
+ old_renamed = nil
108
109
  Tempfile.open(base_name, parent_dir) do |temp_file|
109
110
  begin
110
111
  # Write content to temp file
@@ -117,16 +118,27 @@ module Longleaf
117
118
  old_stat = File.stat(file_path)
118
119
  set_perms(temp_path, old_stat)
119
120
 
120
- begin
121
- digest_paths = write_digests(temp_path, content, digest_algs)
122
-
123
- File.rename(temp_path, file_path)
124
- rescue => e
125
- cleanup_digests(temp_path)
126
- raise e
127
- end
121
+ # Produce digest files for the temp file
122
+ digest_paths = write_digests(temp_path, content, digest_algs)
123
+
124
+ # Move the old file to a temp path in case it needs to be restored
125
+ old_renamed = temp_path + ".old"
126
+ File.rename(file_path, old_renamed)
127
+
128
+ # Move move the new file into place as the new main file
129
+ File.rename(temp_path, file_path)
128
130
  rescue => e
129
- temp_file.delete
131
+ # Attempt to restore old file if it had already been moved
132
+ if !old_renamed.nil? && !File.exist?(file_path)
133
+ File.rename(old_renamed, file_path)
134
+ end
135
+ # Cleanup the temp file and any digest files written for it
136
+ temp_file.delete if File.exist?(temp_file.path)
137
+ unless digest_paths.nil?
138
+ digest_paths.each do |digest_path|
139
+ File.delete(digest_path)
140
+ end
141
+ end
130
142
  raise e
131
143
  end
132
144
 
@@ -136,6 +148,8 @@ module Longleaf
136
148
  digest_paths.each do |digest_path|
137
149
  File.rename(digest_path, digest_path.sub(temp_path, file_path))
138
150
  end
151
+ # Cleanup the old file
152
+ File.delete(old_renamed)
139
153
  end
140
154
  end
141
155
  end
@@ -1,3 +1,3 @@
1
1
  module Longleaf
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: longleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Pennell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor