Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: SMB not respecting calls to os.Chtimes (from windows) #33886

Open
spf13 opened this issue Aug 27, 2019 · 2 comments
Open

os: SMB not respecting calls to os.Chtimes (from windows) #33886

spf13 opened this issue Aug 27, 2019 · 2 comments

Comments

@spf13
Copy link
Contributor

@spf13 spf13 commented Aug 27, 2019

Mentioned in #31880

What version of Go are you using (go version)?

$ go version go1.12.7 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

amd64
windows

What did you do?

I wrote a program that copies media files from one location to another and sets the ctime and mtime to the original file timestamp. The program copies a file and changes the date using io.Copy(destFile, srcFile) then calls os.Chtimes(dest, t.AccessTime(), t.ModTime()) to set the dates.

What did you expect to see?

The dates to change to the dates provided... or an error at least. This silently fails.

What did you see instead?

It works appropriately in most cases, but when copying from a windows machine to a Linux SMB server the destination date is always set to now instead of changing to the src date.

It works from Windows to Windows and from Mac to Mac. I haven't tried other combinations yet.

@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Aug 29, 2019

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Dec 27, 2019

I could reproduce this problem, but only in very special circumstances.

I could not reproduce the problem, if I do file time stamp reading from Windows. I used both os.File.Stat and shelling out with cmd.exe /c dir ... for every test program I tried, and time stamps are as expected. I could only reproduce this problem, if I create file from Windows Go program, and then use stat or ls -l command on Linux to view created file times.

I managed reproduce the problem with this program https://play.golang.org/p/OVLuYilFE7E

But, if I add f.Close() after line 39, the problem goes away.

I can also make problem go away, if I add

        err = f.Sync()
        if err != nil {
                t.Fatal(err)
        }

after line 39.

I don't know @spf13 what your problem is (you did not provide your program), but I suspect that Samba updates modtime when file is written to, but writes might be buffered on the client side. On the other hand, Samba Windows SetFileTime API implementation (Go uses SetFileTime to implement os.Chtimes) is not buffered.

I am not sure if there is anything more we could do here.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.