github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/synchronization/version.go (about)

     1  package synchronization
     2  
     3  import (
     4  	"math"
     5  
     6  	"github.com/mutagen-io/mutagen/pkg/filesystem"
     7  	"github.com/mutagen-io/mutagen/pkg/filesystem/behavior"
     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  // DefaultVersion is the default session version.
    15  const DefaultVersion Version = Version_Version1
    16  
    17  // Supported indicates whether or not the session version is supported.
    18  func (v Version) Supported() bool {
    19  	switch v {
    20  	case Version_Version1:
    21  		return true
    22  	default:
    23  		return false
    24  	}
    25  }
    26  
    27  // DefaultSynchronizationMode returns the default synchronization mode for the
    28  // session version.
    29  func (v Version) DefaultSynchronizationMode() core.SynchronizationMode {
    30  	switch v {
    31  	case Version_Version1:
    32  		return core.SynchronizationMode_SynchronizationModeTwoWaySafe
    33  	default:
    34  		panic("unknown or unsupported session version")
    35  	}
    36  }
    37  
    38  // DefaultHashingAlgorithm returns the default hashing algorithm for the session
    39  // version.
    40  func (v Version) DefaultHashingAlgorithm() hashing.Algorithm {
    41  	switch v {
    42  	case Version_Version1:
    43  		return hashing.Algorithm_AlgorithmSHA1
    44  	default:
    45  		panic("unknown or unsupported session version")
    46  	}
    47  }
    48  
    49  // DefaultMaximumEntryCount returns the default maximum entry count for the
    50  // session version.
    51  func (v Version) DefaultMaximumEntryCount() uint64 {
    52  	switch v {
    53  	case Version_Version1:
    54  		return math.MaxUint64
    55  	default:
    56  		panic("unknown or unsupported session version")
    57  	}
    58  }
    59  
    60  // DefaultMaximumStagingFileSize returns the default maximum staging file size
    61  // for the session version.
    62  func (v Version) DefaultMaximumStagingFileSize() uint64 {
    63  	switch v {
    64  	case Version_Version1:
    65  		return math.MaxUint64
    66  	default:
    67  		panic("unknown or unsupported session version")
    68  	}
    69  }
    70  
    71  // DefaultProbeMode returns the default probe mode for the session version.
    72  func (v Version) DefaultProbeMode() behavior.ProbeMode {
    73  	switch v {
    74  	case Version_Version1:
    75  		return behavior.ProbeMode_ProbeModeProbe
    76  	default:
    77  		panic("unknown or unsupported session version")
    78  	}
    79  }
    80  
    81  // DefaultScanMode returns the default scan mode for the session version.
    82  func (v Version) DefaultScanMode() ScanMode {
    83  	switch v {
    84  	case Version_Version1:
    85  		return ScanMode_ScanModeAccelerated
    86  	default:
    87  		panic("unknown or unsupported session version")
    88  	}
    89  }
    90  
    91  // DefaultStageMode returns the default staging mode for the session version.
    92  func (v Version) DefaultStageMode() StageMode {
    93  	switch v {
    94  	case Version_Version1:
    95  		return StageMode_StageModeMutagen
    96  	default:
    97  		panic("unknown or unsupported session version")
    98  	}
    99  }
   100  
   101  // DefaultSymbolicLinkMode returns the default symbolic link mode for the
   102  // session version.
   103  func (v Version) DefaultSymbolicLinkMode() core.SymbolicLinkMode {
   104  	switch v {
   105  	case Version_Version1:
   106  		return core.SymbolicLinkMode_SymbolicLinkModePortable
   107  	default:
   108  		panic("unknown or unsupported session version")
   109  	}
   110  }
   111  
   112  // DefaultWatchMode returns the default watch mode for the session version.
   113  func (v Version) DefaultWatchMode() WatchMode {
   114  	switch v {
   115  	case Version_Version1:
   116  		return WatchMode_WatchModePortable
   117  	default:
   118  		panic("unknown or unsupported session version")
   119  	}
   120  }
   121  
   122  // DefaultWatchPollingInterval returns the default watch polling interval for
   123  // the session version.
   124  func (v Version) DefaultWatchPollingInterval() uint32 {
   125  	switch v {
   126  	case Version_Version1:
   127  		return 10
   128  	default:
   129  		panic("unknown or unsupported session version")
   130  	}
   131  }
   132  
   133  // DefaultIgnoreSyntax returns the default ignore syntax for the session
   134  // version.
   135  func (v Version) DefaultIgnoreSyntax() ignore.Syntax {
   136  	switch v {
   137  	case Version_Version1:
   138  		return ignore.Syntax_SyntaxMutagen
   139  	default:
   140  		panic("unknown or unsupported session version")
   141  	}
   142  }
   143  
   144  // DefaultIgnoreVCSMode returns the default VCS ignore mode for the session
   145  // version.
   146  func (v Version) DefaultIgnoreVCSMode() ignore.IgnoreVCSMode {
   147  	switch v {
   148  	case Version_Version1:
   149  		return ignore.IgnoreVCSMode_IgnoreVCSModePropagate
   150  	default:
   151  		panic("unknown or unsupported session version")
   152  	}
   153  }
   154  
   155  // DefaultPermissionsMode returns the default permissions mode for the session
   156  // version.
   157  func (v Version) DefaultPermissionsMode() core.PermissionsMode {
   158  	// NOTE: Due to the hack listed in Configuration.EnsureValid (regarding the
   159  	// computation of the default permissions mode), it would be advisable to
   160  	// keep the default here the same for all session versions. If we want this
   161  	// behavior to differ in the future, then we'd need to thread the session
   162  	// version information into Configuration.EnsureValid, because the default
   163  	// can affect the validation of default file and directory modes. This hack
   164  	// could be replaced by looser validation on the default file and directory
   165  	// modes, at least in the scenario where a default permissions mode is used
   166  	// (which is most cases, unfortunately), but since we don't have any
   167  	// foreseeable reason to change this default across future session versions,
   168  	// we're best off keeping the stricter validation for now. We could also
   169  	// change the signature of Configuration.EnsureValid to accept a session
   170  	// version, but that rapidly spirals into other APIs and it's not even clear
   171  	// how to enforce that the daemon's default session version is what's being
   172  	// used for validation in the command line interface or external tools.
   173  	switch v {
   174  	case Version_Version1:
   175  		return core.PermissionsMode_PermissionsModePortable
   176  	default:
   177  		panic("unknown or unsupported session version")
   178  	}
   179  }
   180  
   181  // DefaultFileMode returns the default file permission mode for the session
   182  // version.
   183  func (v Version) DefaultFileMode() filesystem.Mode {
   184  	switch v {
   185  	case Version_Version1:
   186  		return filesystem.ModePermissionUserRead |
   187  			filesystem.ModePermissionUserWrite
   188  	default:
   189  		panic("unknown or unsupported session version")
   190  	}
   191  }
   192  
   193  // DefaultDirectoryMode returns the default directory permission mode for the
   194  // session version.
   195  func (v Version) DefaultDirectoryMode() filesystem.Mode {
   196  	switch v {
   197  	case Version_Version1:
   198  		return filesystem.ModePermissionUserRead |
   199  			filesystem.ModePermissionUserWrite |
   200  			filesystem.ModePermissionUserExecute
   201  	default:
   202  		panic("unknown or unsupported session version")
   203  	}
   204  }
   205  
   206  // DefaultOwnerSpecification returns the default owner specification for the
   207  // session version.
   208  func (v Version) DefaultOwnerSpecification() string {
   209  	switch v {
   210  	case Version_Version1:
   211  		return ""
   212  	default:
   213  		panic("unknown or unsupported session version")
   214  	}
   215  }
   216  
   217  // DefaultGroupSpecification returns the default owner group specification for
   218  // the session version.
   219  func (v Version) DefaultGroupSpecification() string {
   220  	switch v {
   221  	case Version_Version1:
   222  		return ""
   223  	default:
   224  		panic("unknown or unsupported session version")
   225  	}
   226  }
   227  
   228  // DefaultCompressionAlgorithm returns the default compression algorithm for the
   229  // session version.
   230  func (v Version) DefaultCompressionAlgorithm() compression.Algorithm {
   231  	switch v {
   232  	case Version_Version1:
   233  		return compression.Algorithm_AlgorithmDeflate
   234  	default:
   235  		panic("unknown or unsupported session version")
   236  	}
   237  }