Go file operations library chasing GNU APIs.

Related tags

File Handling flop
Overview

flop

GoDoc MIT license Mentioned in Awesome Go Go Report Card


flop aims to make copying files easier in Go, and is modeled after GNU cp. Most administrators and engineers interact with GNU utilities every day, so it makes sense to utilize that knowledge and expectations for a library that does the same operation in code.

flop strategically diverges from cp where it is advantageous for the programmer to explicitly define the behavior, like cp assuming that copying from a file path to a directory path means the file should be created inside the directory. This behavior must be explicitly defined in flop by passing the option AppendNameToPath, otherwise an error will be returned.

go get -u github.com/homedepot/flop

Usage

Basic file copy.

err := flop.SimpleCopy("src_path", "dst_path")
handle(err)

Advanced file copy with options.

options := flop.Options{
    Recursive: true,
    MkdirAll:  true,
}
err := flop.Copy("src_path", "dst_path", options)
handle(err)

Logging

flop won't throw logs at you for no reason, but if you want to follow along with what's going on giving it a logger can help expose the behavior, or aid in debugging if you are generous enough to contribute.

// the logger just takes a string so format your favorite logger to accept one
import (
	"github.com/homedepot/flop"
	"github.com/rs/zerolog"
	zlog "github.com/rs/zerolog/log"
	llog "github.com/sirupsen/logrus"
)

func logDebug(msg string) {
	llog.WithFields(llog.Fields{
		"application": "stuffcopy",
	}).Info(msg)
}

func main() {
	zlog.Logger = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})
	err := flop.Copy(src.Name(), dst.Name(), flop.Options{
		InfoLogFunc: zlog.Info().Msg,  // Msg already accepts a string so we can just pass it directly
		DebugLogFunc: logDebug,        // logrus Debug takes ...interface{} so we need to wrap it
	})
	handle(err)
}
Issues
  • Doesn't close file after copy

    Doesn't close file after copy

    First of all, thank you for this library, it goes a few steps beyond ioutil and I was getting tired of writing a bunch of helper setup code to run test code that modifies the file system, especially high-level testing of binaries.

    However, I got a problem... I copied a directory with some executables as part of a test setup code. When I tried to run one of the copied executables, I got:

    Received unexpected error:
    fork/exec /tmp/upgrade-manager-test484338219/upgrade_manager/genesis/bin/dummyd: text file busy
    

    After digging into some issues, this seems to happen if it was writen, but not closed, and digging into the code, this seems to be the case if the Atomic option was not set. I think you need a dstFile.Close() here: https://github.com/homedepot/flop/blob/master/copy.go#L288

    Current work-around is to pass in flop.Options{Atomic: true} and this will produce a closed file and no such error.

    opened by ethanfrey 3
  •  undefined: setPermissions on Mac

    undefined: setPermissions on Mac

    # github.com/homedepot/flop
    ../../../../pkg/mod/github.com/homedepot/[email protected]/copy.go:294:9: undefined: setPermissions
    
    $ go version                                                       
    go version go1.16.3 darwin/amd64
    
    opened by snipem 1
  • Update permlinux.go to work on MacOS

    Update permlinux.go to work on MacOS

    Make flop work on MacOS. I used a SimpleCopy, and it worked fine. Happy to test more, if needed.

    opened by dilchenko 1
  • reduced size of logo

    reduced size of logo

    opened by EJKinger 1
  • Correct Awesome-Go badge

    Correct Awesome-Go badge

    opened by swtch1 0
  • Issue 17

    Issue 17

    Add close for the destination file descriptor on non-atomic copy.

    opened by swtch1 0
  • logo transparency

    logo transparency

    opened by swtch1 0
  • README updates

    README updates

    opened by swtch1 0
  • Logo

    Logo

    opened by swtch1 0
Owner
The Home Depot
The Home Depot
File system event notification library on steroids.

notify Filesystem event notification library on steroids. (under active development) Documentation godoc.org/github.com/rjeczalik/notify Installation

Rafal Jeczalik 708 Jan 10, 2022
Go library for the TOML file format

Go-toml provides the following features for using data parsed from TOML documents

Thomas Pelletier 1.1k Jan 19, 2022
goelftools is library written in Go for parsing ELF file.

goelftools goelftools is library written in Go for parsing ELF file. This library is inspired by pyelftools and rbelftools. Motivation The motivation

null 23 Oct 11, 2021
Abstract File Storage

afs - abstract file storage Please refer to CHANGELOG.md if you encounter breaking changes. Motivation Introduction Usage Matchers Content modifiers S

Viant, Inc 173 Jan 23, 2022
a tool for handling file uploads simple

baraka a tool for handling file uploads for http servers makes it easier to make operations with files from the http request. Contents Install Simple

Enes Furkan Olcay 36 Dec 30, 2021
Bigfile -- a file transfer system that supports http, rpc and ftp protocol https://bigfile.site

Bigfile ———— a file transfer system that supports http, rpc and ftp protocol 简体中文 ∙ English Bigfile is a file transfer system, supports http, ftp and

null 213 Dec 31, 2021
Read csv file from go using tags

go-csv-tag Read csv file from Go using tags The project is in maintenance mode. It is kept compatible with changes in the Go ecosystem but no new feat

Louis 94 Jan 16, 2022
Pluggable, extensible virtual file system for Go

vfs Package vfs provides a pluggable, extensible, and opinionated set of file system functionality for Go across a number of file system types such as

C2FO 147 Jan 5, 2022
An epoll(7)-based file-descriptor multiplexer.

poller Package poller is a file-descriptor multiplexer. Download: go get github.com/npat-efault/poller Package poller is a file-descriptor multiplexer

Nick Patavalis 105 Nov 15, 2021
QueryCSV enables you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to a CSV file

QueryCSV enable you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to CSV file

Mohamed Shapan 100 Dec 22, 2021
Goful is a CUI file manager written in Go.

Goful Goful is a CUI file manager written in Go. Works on cross-platform such as gnome-terminal and cmd.exe. Displays multiple windows and workspaces.

anmitsu 251 Jan 20, 2022
Read a tar file contents using go1.16 io/fs abstraction

go-tarfs Read a tar file contents using go1.16 io/fs abstraction Usage ⚠️ go-tarfs needs go>=1.16 Install: go get github.com/nlepage/go-tarfs Use: pac

Nicolas Lepage 16 Dec 14, 2021
Open Source Continuous File Synchronization

Goals Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers. We strive to fulfill the goals belo

The Syncthing Project 42.5k Jan 15, 2022
Cross-platform file system notifications for Go.

File system notifications for Go fsnotify utilizes golang.org/x/sys rather than syscall from the standard library. Ensure you have the latest version

fsnotify 6.4k Jan 20, 2022
The best HTTP Static File Server, write with golang+vue

gohttpserver Goal: Make the best HTTP File Server. Features: Human-friendly UI, file uploading support, direct QR-code generation for Apple & Android

Sound Sun 1.4k Jan 23, 2022
Dragonfly is an intelligent P2P based image and file distribution system.

Dragonfly Note: The master branch may be in an unstable or even broken state during development. Please use releases instead of the master branch in o

dragonflyoss 5.7k Jan 17, 2022
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature

filetype Small and dependency free Go package to infer file and MIME type checking the magic numbers signature. For SVG file type checking, see go-is-

Tom 1.5k Jan 17, 2022
📂 Web File Browser

filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files.

File Browser 14.3k Jan 22, 2022
Plik is a scalable & friendly temporary file upload system ( wetransfer like ) in golang.

Want to chat with us ? Telegram channel : https://t.me/plik_root_gg Plik Plik is a scalable & friendly temporary file upload system ( wetransfer like

root.gg 810 Jan 16, 2022