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)
}
You might also like...
Goful is a CUI file manager written in Go.
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.

Read a tar file contents using go1.16 io/fs abstraction
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

Open Source Continuous File Synchronization
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

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

The best HTTP Static File Server, write with golang+vue
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

Dragonfly is an intelligent P2P based image and file distribution system.
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

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-

📂 Web File Browser
📂 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.

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

Comments
  • 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
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 768 Nov 19, 2022
Go library for the TOML file format

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

Thomas Pelletier 1.3k Nov 16, 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 28 Oct 31, 2022
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 213 Nov 18, 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 45 Nov 13, 2022
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 233 Oct 28, 2022
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 101 Nov 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 204 Nov 21, 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 107 Sep 25, 2022
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