Documentation
¶
Overview ¶
Copyright 2014 Joel Scoble (github.com/mohae) All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2014 Joel Scoble (github.com/mohae) All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Based on Richard Clayton's blog post on pipelines:
https://rclayton.silvrback.com/pipelines-in-golang
Which is based on Sameer Ajmani's pipeline post:
https://blog.golang.org/pipelines
Copyright 2014 Joel Scoble (github.com/mohae) All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
This file generates the test directories and files for various testing. This may be refactored to its own package, at some point as it'll probably appear in more than one place.
Index ¶
- Constants
- Variables
- func Delta() float64
- func DisableLog()
- func DstFileData() map[string]*FileData
- func EqualityType(s string) equalityType
- func Log(v ...interface{})
- func Logf(format string, v ...interface{})
- func Message() string
- func ParseHashType(s string) hashType
- func Pull(src, dst string) (string, error)
- func Push(src, dst string) (string, error)
- func SetCPUMultiplier(i int)
- func SetChunkSize(i int)
- func SetDelete(b bool)
- func SetEqualityType(e equalityType)
- func SetHashType(s string)
- func SetLogger(l io.Writer)
- func SetVerbose(b bool)
- func SetVerboseLogger(l io.Writer)
- func WriteTestFiles() (dir string, err error)
- type ArchivedSynch
- type ByPath
- type BySize
- type FileData
- type FileDatas
- type Hash256
- type Pipe
- type Pipeline
- type StringFilter
- type Synch
- func (s *Synch) Delta() float64
- func (s *Synch) DstFileData() map[string]*FileData
- func (s *Synch) Message() string
- func (s *Synch) Pull(src, dst string) (string, error)
- func (s *Synch) Push(src, dst string) (string, error)
- func (s *Synch) SetEqualityType(e equalityType)
- func (s *Synch) SetHashChunkSize(i int)
- func (s *Synch) SetMaxProcs(i int)
- func (s *Synch) Stop() error
- type TimeFilter
Constants ¶
const ( UnknownEquality equalityType = iota BasicEquality // compare bytes for equality check DigestEquality // compare digests for equality check: digest entire file at once ChunkedEquality // compare digests for equality check digest using chunks )
const (
SHA256 hashType
)
Variables ¶
var FName, FData []string
Files
var MaxChunks = 4 // Modify directly to change buffered hashes
var ReadAll = true
var VLogger *log.Logger // Use separate logger for verbose output
Functions ¶
func DisableLog ¶
func DisableLog()
func DstFileData ¶
DstFileData returns the map of FileData accumulated during the walk of the destination.
func EqualityType ¶
func EqualityType(s string) equalityType
func Log ¶
func Log(v ...interface{})
Use for verbose output. Anything using Log() is for Verbosity.
func Logf ¶
func Logf(format string, v ...interface{})
Use for verbose output. Anything using Logf() is for Verbosity.
func ParseHashType ¶
func ParseHashType(s string) hashType
ParseHashType returns the hashType for a given string.
func Push ¶
Push pushes the contents of src to dst.
- Existing files that are the same are ignored
- Modified files are overwritten, even if dst is newer
- New files are created.
- Files in destination not in source may be deleted.
func SetCPUMultiplier ¶
func SetCPUMultiplier(i int)
SetCPUMultiplier sets both the multipler and the maxProcs. If the multiplier is <= 0, 1 is used
func SetChunkSize ¶
func SetChunkSize(i int)
SetChunkSize sets the chunkSize as 1k * i, i.e. 4 == 4k chunkSize If the multiplier, i, is < 0, the default is used, 4.
func SetDelete ¶
func SetDelete(b bool)
SetDelete is used to set the mainSynchro's delete flag. When working directly with a Synchro object, just set it, Synchro.Delete, instead of calling this function.
func SetEqualityType ¶
func SetEqualityType(e equalityType)
func SetHashType ¶
func SetHashType(s string)
SetHashType sets the hashtype to use based on the passed value.
func SetVerbose ¶
func SetVerbose(b bool)
SetVerbose sets the verbosity, a false also sets output to ioutil.Discard, true sets output to stdout.
func SetVerboseLogger ¶
SetVerboseLogger set's the output for the verbose logger. It also sets the verbose flag.
func WriteTestFiles ¶
Types ¶
type ArchivedSynch ¶
type ArchivedSynch struct { Synch *Synch ArchiveDst bool ArchiveFilename string Pipeline // contains filtered or unexported fields }
Synchro provides information about a sync operation. This trades memory for CPU.
func NewArchivedSynch ¶
func NewArchivedSynch() *ArchivedSynch
New returns an initialized ArchivedSynch. Any overrides need to be done prior to a Synch operation. Archived synchs result in an archive of the files, in the destination, that will be updated, modified, or deleted prior to making any modifications to the destination directory.
If the archived synch process encounters an error, the process will be aborted. This may result in the destination directory being in an unknown state, but it should never result in the original destination files being lost or be in an unknown state.
TODO: Add destination state info to archive so that a rollback process can properly restore the destination directory to its pre-synch state using the created archive. The complete inventory is needed so that new files can be removed during the rollback.
type FileData ¶
type FileData struct { Processed bool Digests []Hash256 CurByte int64 // for when the while file hasn't been hashed and Root string // the relative root of this file: allows for synch support Dir string // relative path to parent directory of Fi Buf *bytes.Buffer // Cache read files; trade memory for io BufPos int64 // position in buffer Fi os.FileInfo // contains filtered or unexported fields }
func NewFileData ¶
Returns a FileData struct for the passed file using the defaults. Set any overrides before performing an operation.
func (*FileData) RelPath ¶
RelPath returns the relative path of the file, this is the file less the root information. This allows for easy comparision between two directories.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
func NewPipeline ¶
type StringFilter ¶
type StringFilter struct { Prefix string Ext []string ExtCount int Anchored string // contains filtered or unexported fields }
StringFilter defines the string filters used on files.
type Synch ¶
type Synch struct { // ArchiveDst bool // Archive Destination files that will be modified or deleted // ArchiveFilename string // ArchiveFilename defaults to: archive-2006-01-02:15:04:05-MST.tgz Delete bool // Delete orphaned dst filed (doesn't exist in src) PreserveProperties bool // Preserve file properties(mode, mtime) ReadAll bool // Read the entire file at once; false == chunked read // processingSrc bool // if false, processing dst. Only used for walking Mod int64 // filemode 𝛥t float64 // Change in time between start and end of operation // contains filtered or unexported fields }
Synchro provides information about a sync operation. This trades memory for CPU.
func NewSynch ¶
func NewSynch() *Synch
New returns an initialized Synchro. Any overrides need to be done prior to a Synchro operation.
func (*Synch) DstFileData ¶
DstFileData returns the map of FileData accumulated during the walk of the destination.
func (*Synch) Push ¶
Push pushes the contents of src to dst.
- Existing files that are the same are ignored
- Modified files are overwritten, even if dst is newer
- New files are created.
- Files in destination not in source may be deleted.
func (*Synch) SetEqualityType ¶
func (s *Synch) SetEqualityType(e equalityType)
func (*Synch) SetHashChunkSize ¶
SetDigestChunkSize either sets the chunkSize, when a value > 0 is received, using the recieved int as a multipe of 1024 bytes. If the received value is 0, it will use the current chunksize * 4.
func (*Synch) SetMaxProcs ¶
SetMaxProcs sets the maxProcs to the passed value, or 1 for <= 0.