• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

atomic is a go package for atomic file writing

atomic

import "github.com/natefinch/atomic"

atomic is a go package for atomic file writing

By default, writing to a file in go (and generally any language) can fail partway through... you then have a partially written file, which probably was truncated when the write began, and bam, now you've lost data.

This go package avoids this problem, by writing first to a temp file, and then overwriting the target file in an atomic way. This is easy on linux, os.Rename just is atomic. However, on Windows, os.Rename is not atomic, and so bad things can happen. By wrapping the windows API moveFileEx, we can ensure that the move is atomic, and we can be safe in knowing that either the move succeeds entirely, or neither file will be modified.

func ReplaceFile

func ReplaceFile(source, destination string) error

ReplaceFile atomically replaces the destination file or directory with the source. It is guaranteed to either replace the target file entirely, or not change either file.

func WriteFile

func WriteFile(filename string, r io.Reader) (err error)

WriteFile atomically writes the contents of r to the specified filepath. If an error occurs, the target file is guaranteed to be either fully written, or not written at all. WriteFile overwrites any file that exists at the location (but only if the write fully succeeds, otherwise the existing file is unmodified).

More Repositories

1

lumberjack

lumberjack is a log rolling package for Go
Go
4,272
star
2

gorram

It's like go run for any go function
Go
1,038
star
3

pie

a toolkit for creating plugins for Go applications
Go
747
star
4

npipe

A Windows named pipe implementation written in pure Go.
Go
282
star
5

deputy

deputy is a go package that adds smarts on top of os/exec
Go
230
star
6

godocgo

An example of good godoc documentation.
Go
154
star
7

gocog

Generate code for any language, with any language.
Go
68
star
8

sh

Package sh makes working with shell commands more shell-like. Inspired by https://github.com/amoffat/sh
Go
52
star
9

npf

code to host a professional site
CSS
52
star
10

graffiti

graffiti is a tool to automatically add struct tags to fields in your go code
Go
38
star
11

claymud

Highly configurable and performant MUD written in Go
Go
28
star
12

keep

Go bindings wrapping the Google Keep API
Go
22
star
13

diceware

an implementation of the diceware passphrase generation algorithm
Go
21
star
14

blogimport

A tool to import from Blogger to Hugo
Go
20
star
15

tree

A statically typed binary tree in Go without casts or reflection
Go
19
star
16

pcgrep

Go
15
star
17

covergen

autogenerate a coverage badge for your README with with one dumb trick
Go
10
star
18

convert

An application to convert and resize images written in Go.
Go
10
star
19

plugman

a plugin manifest manager for go
9
star
20

q

Q is a CLI tool for developers that can do anything.
Go
8
star
21

avl

Go
6
star
22

natefinch.github.io

nate's sweet website
HTML
5
star
23

tod

A Hugo site for my D&D campaign
CSS
4
star
24

filterr

go package that helps filter returned errors to a specific list
Go
4
star
25

wrap

Wrap contains a method for wrapping one Go error with another.
Go
4
star
26

Ashes2Ashes

A modified CircleMUD that ran in the late 90's.
C
3
star
27

cavalier

a command line interface generator for Go
Go
3
star
28

emojis-and-dragons

2
star
29

nolog

just a dumb little tool to run juju tests and filter out all the logging
Go
2
star
30

natefinch

1
star
31

harvard-4-h

CSS
1
star
32

rpg

a personal website about RPGs
CSS
1
star
33

circle2json

converts CircleMUD room definitions to json equivalents
Go
1
star
34

go-quickstart

Go
1
star
35

burningchrome

A website for the in-development Burning Chrome RPG.
CSS
1
star
36

eg

An enhanced error package for Go
Go
1
star
37

tabletop.design

HTML
1
star
38

treesample

Sample project using natefinch/tree
Go
1
star