Skip to content

Commit

Permalink
Version Bump, v0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-huxtable committed Nov 24, 2019
1 parent 5fc949c commit 0ba7679
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
7 changes: 3 additions & 4 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: atomic_write
version: 0.1.3
version: 0.1.4
license: ISC

crystal: 0.24.2
crystal: 0.25.1

authors:
- Chris Huxtable <chris@huxtable.ca>

description: |
Extends `File` to provide `atomic_write()`
license: ISC
11 changes: 3 additions & 8 deletions spec/atomic_write_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@ require "tempfile"

require "../src/atomic_write"

private def tempname
time = Time.now.to_s("%Y%m%d")
rand = Random.rand(0x100000000).to_s(36)
File.join("/tmp", "#{time}-#{Process.pid}-#{rand}")
end

describe File do
describe "atomic_write" do
it "writes atomically" do
filename = tempname()
filename = Tempfile.tempname
begin
File.atomic_write(filename) { |fd| fd << "hello" }
File.read(filename).should eq("hello")
Expand All @@ -36,7 +31,7 @@ describe File do
end

it "appends atomically" do
filename = tempname()
filename = Tempfile.tempname
begin
File.atomic_write(filename) { |fd| fd << "hello" }
File.read(filename).should eq("hello")
Expand All @@ -49,7 +44,7 @@ describe File do
end

it "copies atomically" do
filename = tempname()
filename = Tempfile.tempname
copyname = filename + ".copy"
begin
File.atomic_write(filename) { |fd| fd << "hello" }
Expand Down
21 changes: 4 additions & 17 deletions src/atomic_write.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class File
# FIXME: Remove support for 0.24.2 and earlier
{% if compare_versions(Crystal::VERSION, "0.25.0") == -1 %}
DEFAULT_CREATE_PERMISSIONS = DEFAULT_CREATE_MODE
{% end %}

# Ensures the content written to the file descriptor is written completely or not at all
# preventing corruption of the file.
Expand All @@ -43,19 +39,10 @@ class File
raise ex
end

# FIXME: Remove support for 0.24.2 and earlier
{% if compare_versions(Crystal::VERSION, "0.25.0") == -1 %}
if exists?(path)
info = stat(path)
chmod(atomic_path, info.mode)
chown(atomic_path, info.uid, info.gid)
end
{% else %}
if info = info?(path)
chmod(atomic_path, info.permissions)
chown(atomic_path, info.owner, info.group)
end
{% end %}
if info = info?(path)
chmod(atomic_path, info.permissions)
chown(atomic_path, info.owner, info.group)
end

rename(atomic_path, path)
end
Expand Down

0 comments on commit 0ba7679

Please sign in to comment.