sync

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NetworkAdapter

type NetworkAdapter interface {
	OpenTransaction(transactionName string, uuid string) (Transaction, error)
}

type Repository

type Repository interface {
	SaveRootDir(afterPath string, rootDir *types.RootDirectory) error
	GetRootDirByPath(afterPath string) (*types.RootDirectory, error)
	GetAllRootDir() ([]types.RootDirectory, error)

	IsExistFileByPath(afterPath string) (bool, error)
	SaveFileByPath(afterPath string, file *types.File) error
	GetFileByPath(afterPath string) (*types.File, error)
	UpdateFile(file *types.File) error
	GetAllFiles(prefix string) ([]types.File, error)

	UpdateConflict(afterpath string, conflict *types.Conflict) error
	GetConflict(afterpath string) (*types.Conflict, error)
	GetConflictList(rootDirs []string) ([]types.Conflict, error)
	DeleteConflict(afterpath string) error

	ErrKeyNotFound() error
}

type Service

type Service interface {
	RegisterRootDir(request *types.RootDirRegisterReq) (*types.RootDirRegisterRes, error)
	SyncRootDir(request *types.RootDirRegisterReq) (*types.RootDirRegisterRes, error)
	GetRootDirList() (*types.AskRootDirRes, error)
	GetRootDirByPath(afterPath string) (*types.RootDirectory, error)
	DisconnectRootDir(request *types.DisconnectRootDirReq) (*types.DisconnectRootDirRes, error)

	UpdateFileWithoutContents(pleaseSyncReq *types.PleaseSyncReq) (*types.PleaseSyncRes, error)
	UpdateFileWithContents(pleaseTakeReq *types.PleaseTakeReq, fileMetadata *types.FileMetadata, fileContent io.Reader) (*types.PleaseTakeRes, error)
	CallMustSync(filePath string, UUIDs []string) error

	GetConflictList(*types.AskConflictListReq) (*types.AskConflictListRes, error)
	ChooseOne(request *types.PleaseFileReq) (*types.PleaseFileRes, error)
	CallForceSync(filePath string, UUIDs []string) error

	FullScan(uuid string) error
	BackgroundFullScan(interval uint64) error
	Rescan(*types.RescanReq) (*types.RescanRes, error)

	GetFilesByRootDir(rootDirPath string) []types.File
	GetFiles() []types.File
	GetFileByPath(afterPath string) (*types.File, error)

	RollbackFileByHistory(request *types.RollBackReq) (*types.RollBackRes, error)

	DownloadHistory(request *types.DownloadHistoryReq) (*types.DownloadHistoryRes, string, error)

	GetStagingNum(request *types.AskStagingNumReq) (*types.AskStagingNumRes, error)
	GetConflictFiles(request *types.AskStagingNumReq) ([]types.ConflictDownloadReq, error)
}

func NewService

func NewService(registrationRepository registration.Repository, historyRepository history.Repository, syncRepository Repository, networkAdapter NetworkAdapter, syncDirAdpater SyncDirAdapter) Service

type SyncDirAdapter

type SyncDirAdapter interface {
	SaveFileToLatestDir(afterPath string, fileMetadata *types.FileMetadata, fileContent io.Reader) error
	GetFileFromLatestDir(afterPath string) (*types.FileMetadata, io.Reader, error)
	DeleteFileFromLatestDir(afterPath string) error
	SaveFileToConflictDir(uuid string, afterPath string, fileMetadata *types.FileMetadata, fileContent io.Reader) error
	GetFileFromConflictDir(afterPath string, uuid string) (*types.FileMetadata, io.Reader, error)
	GetFileInfoFromConflictDir(afterPath string, uuid string) (*types.FileMetadata, error)
	DeleteFilesFromConflictDir(afterPath string) error
	SaveFileToHistoryDir(afterPath string, timestamp uint64, fileMetadata *types.FileMetadata, fileContent io.Reader) error
	GetFileFromHistoryDir(afterPath string, timestamp uint64) (*types.FileMetadata, io.Reader, error)
	GetFileInfoFromHistoryDir(afterPath string, timestamp uint64) (*types.FileMetadata, error)
}

type SyncService

type SyncService struct {
	FSTrigger chan string
	// contains filtered or unexported fields
}

func (*SyncService) BackgroundFullScan

func (ss *SyncService) BackgroundFullScan(secInterval uint64) error

func (*SyncService) CallForceSync

func (ss *SyncService) CallForceSync(filePath string, UUIDs []string) error

func (*SyncService) CallMustSync

func (ss *SyncService) CallMustSync(filePath string, UUIDs []string) error

CallMustSync calls must sync transaction

func (*SyncService) CallNeedContent

func (ss *SyncService) CallNeedContent(file *types.File) error

func (*SyncService) ChooseOne

func (ss *SyncService) ChooseOne(request *types.PleaseFileReq) (*types.PleaseFileRes, error)

func (*SyncService) DisconnectRootDir

func (ss *SyncService) DisconnectRootDir(request *types.DisconnectRootDirReq) (*types.DisconnectRootDirRes, error)

func (*SyncService) DownloadHistory

func (ss *SyncService) DownloadHistory(request *types.DownloadHistoryReq) (*types.DownloadHistoryRes, string, error)

func (*SyncService) FullScan

func (ss *SyncService) FullScan(uuid string) error

func (*SyncService) GetConflictFiles

func (ss *SyncService) GetConflictFiles(request *types.AskStagingNumReq) ([]types.ConflictDownloadReq, error)

func (*SyncService) GetConflictList

func (ss *SyncService) GetConflictList(request *types.AskConflictListReq) (*types.AskConflictListRes, error)

func (*SyncService) GetFileByPath

func (ss *SyncService) GetFileByPath(path string) (*types.File, error)

GetFileByPath returns file entity by path

func (*SyncService) GetFiles

func (ss *SyncService) GetFiles() []types.File

GetFiles returns all files in database

func (*SyncService) GetFilesByRootDir

func (ss *SyncService) GetFilesByRootDir(rootDirPath string) []types.File

GetFilesByRootDir returns files by root directory path

func (*SyncService) GetRootDirByPath

func (ss *SyncService) GetRootDirByPath(path string) (*types.RootDirectory, error)

GetRootDirByPath gets root directory by path

func (*SyncService) GetRootDirList

func (ss *SyncService) GetRootDirList() (*types.AskRootDirRes, error)

GetRootDirList gets root directory list of client

func (*SyncService) GetStagingNum

func (ss *SyncService) GetStagingNum(request *types.AskStagingNumReq) (*types.AskStagingNumRes, error)

func (*SyncService) RegisterRootDir

func (ss *SyncService) RegisterRootDir(request *types.RootDirRegisterReq) (*types.RootDirRegisterRes, error)

RegisterRootDir registers initial root directory to client database

func (*SyncService) Rescan

func (ss *SyncService) Rescan(request *types.RescanReq) (*types.RescanRes, error)

func (*SyncService) RollbackFileByHistory

func (ss *SyncService) RollbackFileByHistory(request *types.RollBackReq) (*types.RollBackRes, error)

func (*SyncService) SyncRootDir

func (ss *SyncService) SyncRootDir(request *types.RootDirRegisterReq) (*types.RootDirRegisterRes, error)

SyncRootDir syncs root directory to other client from owner client

func (*SyncService) UpdateFileWithContents

func (ss *SyncService) UpdateFileWithContents(pleaseTakeReq *types.PleaseTakeReq, fileMetadata *types.FileMetadata, fileContent io.Reader) (*types.PleaseTakeRes, error)

UpdateFileWithContents updates file (ContentExisted = true)

func (*SyncService) UpdateFileWithoutContents

func (ss *SyncService) UpdateFileWithoutContents(pleaseSyncReq *types.PleaseSyncReq) (*types.PleaseSyncRes, error)

UpdateFileWithoutContents updates file (ContentExisted = false)

type Transaction

type Transaction interface {
	RequestMustSync(*types.MustSyncReq) (*types.MustSyncRes, error)
	RequestGiveYou(giveYouReq *types.GiveYouReq, historyFilePath string) (*types.GiveYouRes, error)
	RequestForceSync(mustSyncReq *types.MustSyncReq, historyFilePath string) (*types.MustSyncRes, error)
	RequestAskAllMeta(askAllMetaReq *types.AskAllMetaReq) (*types.AskAllMetaRes, error)
	RequestNeedSync(needSyncReq *types.NeedSyncReq) (*types.NeedSyncRes, error)
	RequestNeedContent(needContentReq *types.NeedContentReq) (*types.NeedContentRes, *types.FileMetadata, io.Reader, error)
	Close() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL