diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index 913600e7..0ece866c 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.36" -const REVISION = "110daef2be989ffe0f7a2111e4a8e75272a4b6d3+1" -const NUMBER = 227 +const REVISION = "fce3dfc3c3587abde57944d6b16030437a9d8ce9+1" +const NUMBER = 228 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index bc384440..a8e7b8a3 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -3,8 +3,8 @@ package main import "fmt" const VERSION = "1.0.36" -const REVISION = "110daef2be989ffe0f7a2111e4a8e75272a4b6d3+1" -const NUMBER = 227 +const REVISION = "fce3dfc3c3587abde57944d6b16030437a9d8ce9+1" +const NUMBER = 228 func getRevision() string { revSuffix := "" diff --git a/runtime/core/version.go b/runtime/core/version.go index 913600e7..0ece866c 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.36" -const REVISION = "110daef2be989ffe0f7a2111e4a8e75272a4b6d3+1" -const NUMBER = 227 +const REVISION = "fce3dfc3c3587abde57944d6b16030437a9d8ce9+1" +const NUMBER = 228 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/support/filecopy/copy.go b/support/filecopy/copy.go index 763ce1fe..bda9f58b 100644 --- a/support/filecopy/copy.go +++ b/support/filecopy/copy.go @@ -258,6 +258,21 @@ func copyDirHandle(srcDir string, targetAbsDir string, opts *copyOptions, handle if isDir { return os.MkdirAll(dstPath, 0755) } + + // handle symlink and other files + typ := d.Type() + if !typ.IsRegular() { + if (typ & fs.ModeSymlink) == 0 { + return nil + } + // create symlink + target, err := os.Readlink(path) + if err != nil { + return err + } + return os.Symlink(target, dstPath) + } + return handler(path, dstPath) }) } diff --git a/support/filecopy/copy_test.go b/support/filecopy/copy_test.go new file mode 100644 index 00000000..b463bbf3 --- /dev/null +++ b/support/filecopy/copy_test.go @@ -0,0 +1,119 @@ +package filecopy + +import ( + "fmt" + "io/fs" + "io/ioutil" + "os" + "path/filepath" + "testing" +) + +func testCopyReplace(prepare func(rootDir string, srcDir string, dstDir string) error, check func(rootDir string, srcDir string, dstDir string) error) error { + tmpDir, err := os.MkdirTemp("", "copy-with-link") + if err != nil { + return err + } + defer os.RemoveAll(tmpDir) + + srcDir := filepath.Join(tmpDir, "src") + err = os.MkdirAll(srcDir, 0755) + if err != nil { + return err + } + dstDir := filepath.Join(tmpDir, "dst") + + err = prepare(tmpDir, srcDir, dstDir) + if err != nil { + return err + } + err = CopyReplaceDir(srcDir, dstDir, false) + if err != nil { + return err + } + if check == nil { + return nil + } + return check(tmpDir, srcDir, dstDir) +} + +func TestCopyWithSymLinkFiles(t *testing.T) { + // doc.txt + // src/ + // a.txt + // doc.txt -> ../doc.txt + err := testCopyReplace(func(rootDir, srcDir, dstDir string) error { + docTxt := filepath.Join(rootDir, "doc.txt") + err := ioutil.WriteFile(docTxt, []byte("doc"), 0755) + if err != nil { + return err + } + + err = ioutil.WriteFile(filepath.Join(srcDir, "a.txt"), []byte("test"), 0755) + if err != nil { + return err + } + err = os.Symlink(docTxt, filepath.Join(srcDir, "doc.txt")) + if err != nil { + return err + } + return nil + }, func(rootDir, srcDir, dstDir string) error { + ok, err := checkIsSymLink(filepath.Join(dstDir, "doc.txt")) + if err != nil { + return err + } + if !ok { + return fmt.Errorf("expect dst/doc.txt to be sym link, actually not") + } + return nil + }) + if err != nil { + t.Fatal(err) + } +} + +func checkIsSymLink(file string) (bool, error) { + finfo, err := os.Lstat(file) + if err != nil { + return false, err + } + if finfo.Mode()&fs.ModeSymlink != 0 { + return true, nil + } + return false, nil +} +func TestCopyWithSymLinkDirs(t *testing.T) { + // doc.txt + // src/ + // a.txt + // doc.txt -> ../doc.txt + err := testCopyReplace(func(rootDir, srcDir, dstDir string) error { + docDir := filepath.Join(rootDir, "doc") + err := os.MkdirAll(docDir, 0755) + if err != nil { + return err + } + err = ioutil.WriteFile(filepath.Join(docDir, "doc.txt"), []byte("doc"), 0755) + if err != nil { + return err + } + err = os.Symlink(docDir, filepath.Join(srcDir, "doc")) + if err != nil { + return err + } + return nil + }, func(rootDir, srcDir, dstDir string) error { + ok, err := checkIsSymLink(filepath.Join(dstDir, "doc")) + if err != nil { + return err + } + if !ok { + return fmt.Errorf("expect dst/doc to be sym link, actually not") + } + return nil + }) + if err != nil { + t.Fatal(err) + } +}