From 43fa256d5636dedde9976e6636dc9fc3097a794c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 12 May 2023 16:29:55 +0100 Subject: [PATCH] fs: add OverrideDirectory for overriding path of directory --- fs/override_dir.go | 34 ++++++++++++++++++++++++++++++++++ fs/override_dir_test.go | 4 ++++ 2 files changed, 38 insertions(+) create mode 100644 fs/override_dir.go create mode 100644 fs/override_dir_test.go diff --git a/fs/override_dir.go b/fs/override_dir.go new file mode 100644 index 000000000..a20651155 --- /dev/null +++ b/fs/override_dir.go @@ -0,0 +1,34 @@ +package fs + +// OverrideDirectory is a wrapper to override the Remote for an +// Directory +type OverrideDirectory struct { + Directory + remote string +} + +// NewOverrideDirectory returns an OverrideDirectoryObject which will +// return the remote specified +func NewOverrideDirectory(oi Directory, remote string) *OverrideDirectory { + // re-wrap an OverrideDirectory + if or, ok := oi.(*OverrideDirectory); ok { + return &OverrideDirectory{ + Directory: or.Directory, + remote: remote, + } + } + return &OverrideDirectory{ + Directory: oi, + remote: remote, + } +} + +// Remote returns the overridden remote name +func (o *OverrideDirectory) Remote() string { + return o.remote +} + +// String returns the overridden remote name +func (o *OverrideDirectory) String() string { + return o.remote +} diff --git a/fs/override_dir_test.go b/fs/override_dir_test.go new file mode 100644 index 000000000..0e23e1b55 --- /dev/null +++ b/fs/override_dir_test.go @@ -0,0 +1,4 @@ +package fs + +// Check interfaces satisfied +var _ Directory = (*OverrideDirectory)(nil)