github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/api/models/synchronization/configuration.go (about) 1 package synchronization 2 3 import ( 4 "github.com/mutagen-io/mutagen/pkg/api/models/types" 5 "github.com/mutagen-io/mutagen/pkg/filesystem" 6 "github.com/mutagen-io/mutagen/pkg/filesystem/behavior" 7 "github.com/mutagen-io/mutagen/pkg/synchronization" 8 "github.com/mutagen-io/mutagen/pkg/synchronization/compression" 9 "github.com/mutagen-io/mutagen/pkg/synchronization/core" 10 "github.com/mutagen-io/mutagen/pkg/synchronization/core/ignore" 11 "github.com/mutagen-io/mutagen/pkg/synchronization/hashing" 12 ) 13 14 // Configuration represents synchronization session configuration. 15 type Configuration struct { 16 // Mode specifies the default synchronization mode. 17 Mode core.SynchronizationMode `json:"mode,omitempty" yaml:"mode" mapstructure:"mode"` 18 // Hash specifies the hashing algorithm to use for content. 19 Hash hashing.Algorithm `json:"hash,omitempty" yaml:"hash" mapstructure:"hash"` 20 // MaximumEntryCount specifies the maximum number of filesystem entries 21 // that endpoints will tolerate managing. 22 MaximumEntryCount uint64 `json:"maxEntryCount,omitempty" yaml:"maxEntryCount" mapstructure:"maxEntryCount"` 23 // MaximumStagingFileSize is the maximum (individual) file size that 24 // endpoints will stage. It can be specified in human-friendly units. 25 MaximumStagingFileSize types.ByteSize `json:"maxStagingFileSize,omitempty" yaml:"maxStagingFileSize" mapstructure:"maxStagingFileSize"` 26 // ProbeMode specifies the filesystem probing mode. 27 ProbeMode behavior.ProbeMode `json:"probeMode,omitempty" yaml:"probeMode" mapstructure:"probeMode"` 28 // ScanMode specifies the filesystem scanning mode. 29 ScanMode synchronization.ScanMode `json:"scanMode,omitempty" yaml:"scanMode" mapstructure:"scanMode"` 30 // StageMode specifies the filesystem staging mode. 31 StageMode synchronization.StageMode `json:"stageMode,omitempty" yaml:"stageMode" mapstructure:"stageMode"` 32 // Ignore contains parameters related to synchronization ignore 33 // specifications. 34 Ignore struct { 35 // Syntax specifies the ignore syntax and semantics. 36 Syntax ignore.Syntax `json:"syntax,omitempty" yaml:"syntax" mapstructure:"syntax"` 37 // Paths specifies the default list of ignore specifications. 38 Paths []string `json:"paths,omitempty" yaml:"paths" mapstructure:"paths"` 39 // VCS specifies the VCS ignore mode. 40 VCS ignore.IgnoreVCSMode `json:"vcs,omitempty" yaml:"vcs" mapstructure:"vcs"` 41 } `json:"ignore" yaml:"ignore" mapstructure:"ignore"` 42 // Symlink contains parameters related to symbolic link handling. 43 Symlink struct { 44 // Mode specifies the symbolic link mode. 45 Mode core.SymbolicLinkMode `json:"mode,omitempty" yaml:"mode" mapstructure:"mode"` 46 } `json:"symlink" yaml:"symlink" mapstructure:"symlink"` 47 // Watch contains parameters related to filesystem monitoring. 48 Watch struct { 49 // Mode specifies the file watching mode. 50 Mode synchronization.WatchMode `json:"mode,omitempty" yaml:"mode" mapstructure:"mode"` 51 // PollingInterval specifies the interval (in seconds) for poll-based 52 // file monitoring. A value of 0 specifies that Mutagen's internal 53 // default interval should be used. 54 PollingInterval uint32 `json:"pollingInterval,omitempty" yaml:"pollingInterval" mapstructure:"pollingInterval"` 55 } `json:"watch" yaml:"watch" mapstructure:"watch"` 56 // Permissions contains parameters related to permission handling. 57 Permissions struct { 58 // Mode specifies the permissions mode. 59 Mode core.PermissionsMode `json:"mode,omitempty" yaml:"mode" mapstructure:"mode"` 60 // DefaultFileMode specifies the default permission mode to use for new 61 // files in "portable" permission propagation mode. 62 DefaultFileMode filesystem.Mode `json:"defaultFileMode,omitempty" yaml:"defaultFileMode" mapstructure:"defaultFileMode"` 63 // DefaultDirectoryMode specifies the default permission mode to use for 64 // new files in "portable" permission propagation mode. 65 DefaultDirectoryMode filesystem.Mode `json:"defaultDirectoryMode,omitempty" yaml:"defaultDirectoryMode" mapstructure:"defaultDirectoryMode"` 66 // DefaultOwner specifies the default owner identifier to use when 67 // setting ownership of new files and directories in "portable" 68 // permission propagation mode. 69 DefaultOwner string `json:"defaultOwner,omitempty" yaml:"defaultOwner" mapstructure:"defaultOwner"` 70 // DefaultGroup specifies the default group identifier to use when 71 // setting ownership of new files and directories in "portable" 72 // permission propagation mode. 73 DefaultGroup string `json:"defaultGroup,omitempty" yaml:"defaultGroup" mapstructure:"defaultGroup"` 74 } `json:"permissions" yaml:"permissions" mapstructure:"permissions"` 75 // Compression contains parameters related to compression. 76 Compression struct { 77 // Algorithm specifies the compression algorithm. 78 Algorithm compression.Algorithm `json:"algorithm,omitempty" yaml:"algorithm" mapstructure:"algorithm"` 79 } `json:"compression" yaml:"compression" mapstructure:"compression"` 80 } 81 82 // loadFromInternal sets a configuration to match an internal 83 // Protocol Buffers representation. The configuration must be valid. 84 func (c *Configuration) loadFromInternal(configuration *synchronization.Configuration) { 85 // Propagate top-level configuration. 86 c.Mode = configuration.SynchronizationMode 87 c.Hash = configuration.HashingAlgorithm 88 c.MaximumEntryCount = configuration.MaximumEntryCount 89 c.MaximumStagingFileSize = types.ByteSize(configuration.MaximumStagingFileSize) 90 c.ProbeMode = configuration.ProbeMode 91 c.ScanMode = configuration.ScanMode 92 c.StageMode = configuration.StageMode 93 94 // Propagate ignore configuration. 95 c.Ignore.Syntax = configuration.IgnoreSyntax 96 c.Ignore.Paths = make([]string, 0, len(configuration.DefaultIgnores)+len(configuration.Ignores)) 97 c.Ignore.Paths = append(c.Ignore.Paths, configuration.DefaultIgnores...) 98 c.Ignore.Paths = append(c.Ignore.Paths, configuration.Ignores...) 99 c.Ignore.VCS = configuration.IgnoreVCSMode 100 101 // Propagate symbolic link configuration. 102 c.Symlink.Mode = configuration.SymbolicLinkMode 103 104 // Propagate watch configuration. 105 c.Watch.Mode = configuration.WatchMode 106 c.Watch.PollingInterval = configuration.WatchPollingInterval 107 108 // Propagate permission configuration. 109 c.Permissions.Mode = configuration.PermissionsMode 110 c.Permissions.DefaultFileMode = filesystem.Mode(configuration.DefaultFileMode) 111 c.Permissions.DefaultDirectoryMode = filesystem.Mode(configuration.DefaultDirectoryMode) 112 c.Permissions.DefaultOwner = configuration.DefaultOwner 113 c.Permissions.DefaultGroup = configuration.DefaultGroup 114 115 // Propagate compression configuration. 116 c.Compression.Algorithm = configuration.CompressionAlgorithm 117 } 118 119 // ToInternal converts a public configuration representation to an internal 120 // Protocol Buffers session configuration. It does not validate the resulting 121 // configuration. 122 func (c *Configuration) ToInternal() *synchronization.Configuration { 123 return &synchronization.Configuration{ 124 SynchronizationMode: c.Mode, 125 HashingAlgorithm: c.Hash, 126 MaximumEntryCount: c.MaximumEntryCount, 127 MaximumStagingFileSize: uint64(c.MaximumStagingFileSize), 128 ProbeMode: c.ProbeMode, 129 ScanMode: c.ScanMode, 130 StageMode: c.StageMode, 131 SymbolicLinkMode: c.Symlink.Mode, 132 WatchMode: c.Watch.Mode, 133 WatchPollingInterval: c.Watch.PollingInterval, 134 IgnoreSyntax: c.Ignore.Syntax, 135 Ignores: c.Ignore.Paths, 136 IgnoreVCSMode: c.Ignore.VCS, 137 PermissionsMode: c.Permissions.Mode, 138 DefaultFileMode: uint32(c.Permissions.DefaultFileMode), 139 DefaultDirectoryMode: uint32(c.Permissions.DefaultDirectoryMode), 140 DefaultOwner: c.Permissions.DefaultOwner, 141 DefaultGroup: c.Permissions.DefaultGroup, 142 CompressionAlgorithm: c.Compression.Algorithm, 143 } 144 }