Skip to content

source directory has suffix will fail#49

Open
yjhi wants to merge 2 commits intogokrazy:mainfrom
yjhi:bug-on-windows
Open

source directory has suffix will fail#49
yjhi wants to merge 2 commits intogokrazy:mainfrom
yjhi:bug-on-windows

Conversation

@yjhi
Copy link

@yjhi yjhi commented Dec 26, 2025

Command:
C:\Users\yyy\Desktop\rsync\111\gokr-rsync.exe -av C:\Users\yyy\Desktop\rsync\111\gg ...server

Log:
2025/12/26 15:17:20 rsyncos.go:32: remote protocol: 31
2025/12/26 15:17:20 rsyncos.go:32: sender(paths=["C:\Users\yyy\Desktop\rsync\111\gg"])
2025/12/26 15:17:20 do.go:43: SendFileList(modPath="\\?\", paths=["C:\Users\yyy\Desktop\rsync\111\gg"])
2025/12/26 15:17:20 flist.go:345: sendFileList()
2025/12/26 15:17:20 flist.go:360: path "C:\Users\yyy\Desktop\rsync\111\gg" (local dir "\\?\")
2025/12/26 15:17:20 flist.go:371: filepath.Walk("\\?\C:\Users\yyy\Desktop\rsync\111\gg"), strip="\\?\C:\Users\yyy\Desktop\rsync\111\"
2025/12/26 15:17:20 flist.go:372: prefix="\gg/"
2025/12/26 15:17:20 flist.go:141: filepath.WalkFn(path=.)
2025/12/26 15:17:20 flist.go:152: isDir=true, xferDirs=1
2025/12/26 15:17:20 flist.go:162: Trim(path=".") = "\gg/."
2025/12/26 15:17:20 flist.go:141: filepath.WalkFn(path=11.txt)
2025/12/26 15:17:20 flist.go:152: isDir=false, xferDirs=1
2025/12/26 15:17:20 flist.go:162: Trim(path="11.txt") = "\gg/11.txt"
2025/12/26 15:17:20 do.go:51: file list sent
2025/12/26 15:17:20 rsyncos.go:32: info: \gg/

Server:
image

yjhi added 2 commits December 26, 2025 16:21
2025/12/26 15:17:20 rsyncos.go:32: remote protocol: 31
2025/12/26 15:17:20 rsyncos.go:32: sender(paths=["C:\\Users\\yyy\\Desktop\\rsync\\111\\gg"])
2025/12/26 15:17:20 do.go:43: SendFileList(modPath="\\\\?\\", paths=["C:\\Users\\yyy\\Desktop\\rsync\\111\\gg"])
2025/12/26 15:17:20 flist.go:345: sendFileList()
2025/12/26 15:17:20 flist.go:360:   path "C:\\Users\\yyy\\Desktop\\rsync\\111\\gg" (local dir "\\\\?\\")
2025/12/26 15:17:20 flist.go:371:   filepath.Walk("\\\\?\\C:\\Users\\yyy\\Desktop\\rsync\\111\\gg"), strip="\\\\?\\C:\\Users\\yyy\\Desktop\\rsync\\111\\"
2025/12/26 15:17:20 flist.go:372:   prefix="\\gg/"
2025/12/26 15:17:20 flist.go:141: filepath.WalkFn(path=.)
2025/12/26 15:17:20 flist.go:152: isDir=true, xferDirs=1
2025/12/26 15:17:20 flist.go:162: Trim(path=".") = "\\gg/."
2025/12/26 15:17:20 flist.go:141: filepath.WalkFn(path=11.txt)
2025/12/26 15:17:20 flist.go:152: isDir=false, xferDirs=1
2025/12/26 15:17:20 flist.go:162: Trim(path="11.txt") = "\\gg/11.txt"
2025/12/26 15:17:20 do.go:51: file list sent
2025/12/26 15:17:20 rsyncos.go:32: info: \gg/
Copy link
Contributor

@stapelberg stapelberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! Is there already a test in the test suite which starts passing with your changes? If not, could you add a test that triggers the bug please?

strip := filepath.Dir(filepath.Clean(root)) + sep
if strings.HasSuffix(requested, sep) {

isEndSep := strings.HasSuffix(requested, "\\") || strings.HasSuffix(requested, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t understand why you had to make this change? os.PathSeparator is defined as / on Linux (see https://pkg.go.dev/os#PathSeparator) and \\ on Windows (see https://pkg.go.dev/os?GOOS=windows#PathSeparator), so why isn’t that enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows systems, paths can use either \ or /

// st.Logger.Printf("root=%q, strip=%q", root, strip)
prefix := strings.TrimPrefix(rootPath, filepath.Clean(strip))
if prefix != "" {
prefix = strings.TrimPrefix(prefix, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use os.PathSeparator here instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing slash on the source directory:
With a slash: sync the contents of the directory
Without a slash: sync the directory itself

// Trailing slashes are meaningful to rsync,
// so preserve a trailing slash across filepath.Abs.
hasTrailingSlash := strings.HasSuffix(path, "/")
hasTrailingSlash := strings.HasSuffix(path, "/") || strings.HasSuffix(path, "\\")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use os.PathSeparator here instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I use gokrazy-rsync on Windows and rsync on Linux, even if the path ends with a separator, the Linux server still creates the path.

@yjhi
Copy link
Author

yjhi commented Jan 4, 2026

Thank you for your contribution! Is there already a test in the test suite which starts passing with your changes? If not, could you add a test that triggers the bug please?

This bug is easy to reproduce. On a Windows system, sync a directory to a Linux server, using rsync on the Linux server and gokr-rsync.exe on Windows.

gokr-rsync.exe -av C:\Users\yyy\Desktop\rsync\111\test\ root@linux_server_ip:~/test
gokr-rsync.exe -av C:\Users\yyy\Desktop\rsync\111\test root@linux_server_ip:~/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants