mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package moxio
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/mail/mlog"
|
|
)
|
|
|
|
func tcheckf(t *testing.T, err error, format string, args ...any) {
|
|
if err != nil {
|
|
t.Helper()
|
|
t.Fatalf("%s: %s", fmt.Sprintf(format, args...), err)
|
|
}
|
|
}
|
|
|
|
func TestLinkOrCopy(t *testing.T) {
|
|
log := mlog.New("linkorcopy", nil)
|
|
|
|
// link in same directory. file exists error. link to file in non-existent
|
|
// directory (exists error). link to file in system temp dir (hopefully other file
|
|
// system).
|
|
src := "linkorcopytest-src.txt"
|
|
f, err := os.Create(src)
|
|
tcheckf(t, err, "creating test file")
|
|
defer os.Remove(src)
|
|
defer f.Close()
|
|
err = LinkOrCopy(log, "linkorcopytest-dst.txt", src, nil, false)
|
|
tcheckf(t, err, "linking file")
|
|
err = os.Remove("linkorcopytest-dst.txt")
|
|
tcheckf(t, err, "remove dst")
|
|
|
|
err = LinkOrCopy(log, "bogus/linkorcopytest-dst.txt", src, nil, false)
|
|
if err == nil || !os.IsNotExist(err) {
|
|
t.Fatalf("expected is not exist, got %v", err)
|
|
}
|
|
|
|
// Try with copying the file. This can currently only really happen on systems that
|
|
// don't support hardlinking. Because other code and tests already use os.Rename on
|
|
// similar files, which will fail for being cross-filesystem (and we do want
|
|
// users/admins to have the mox temp dir on the same file system as the account
|
|
// files).
|
|
dst := filepath.Join(os.TempDir(), "linkorcopytest-dst.txt")
|
|
err = LinkOrCopy(log, dst, src, nil, true)
|
|
tcheckf(t, err, "copy file")
|
|
err = os.Remove(dst)
|
|
tcheckf(t, err, "removing dst")
|
|
|
|
// Copy based on open file.
|
|
_, err = f.Seek(0, 0)
|
|
tcheckf(t, err, "seek to start")
|
|
err = LinkOrCopy(log, dst, src, f, true)
|
|
tcheckf(t, err, "copy file from reader")
|
|
err = os.Remove(dst)
|
|
tcheckf(t, err, "removing dst")
|
|
}
|