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

lib/config: Add file inside folder marker directory #9525

Merged
merged 1 commit into from May 24, 2024

Conversation

calmh
Copy link
Member

@calmh calmh commented May 1, 2024

Purpose

Avoid the issue where the folder marker is deleted by overzealous cleanup tools because it's just a useless, empty directory.

We create a small file containing a an admonishment to not delete the directory, and some metadata that is just for human consumption at the moment. (But it would parse as a valid yaml file if we wanted to read this, at some point.)

This will only apply when creating a folder marker, that is, existing setups will not gain the file automatically. Obviously, when using a custom folder marker none of this applies.

Testing

I've created and deleted a few folders and it appears to behave as I expect.

Screenshots

jb@ok:~/somefolder % ls -la
total 0
drwxr-xr-x   3 jb  staff   96 May  1 08:52 ./
drwx------  12 jb  staff  384 May  1 08:52 ../
drwxr-xr-x   3 jb  staff   96 May  1 08:52 .stfolder/
jb@ok:~/somefolder % ls -l .stfolder
total 8
-rw-r--r--  1 jb  staff  122 May  1 08:52 syncthing-folder-39a4b0.txt
jb@ok:~/somefolder % cat .stfolder/syncthing-folder-39a4b0.txt
# This directory is a Syncthing folder marker.
# Do not delete.

folderID: xtdca-cudyf
created: 2024-05-01T08:52:49+02:00

Copy link
Member

@acolomb acolomb left a comment

Choose a reason for hiding this comment

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

Looks good code-wise. Just a few questions.

I could see more checks being done when finding the marker (e.g. checking whether the folder ID matches, maybe even record and check the device ID?). But it's absolutely OK to skip that in this first step.

func (f *FolderConfiguration) markerContents() []byte {
var buf bytes.Buffer
buf.WriteString("# This directory is a Syncthing folder marker.\n# Do not delete.\n\n")
fmt.Fprintf(&buf, "folderID: %s\n", f.ID)
Copy link
Member

Choose a reason for hiding this comment

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

Also folderLabel, or do you think this info is too fragile (not guaranteed to be immutable)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that, it can change and this file won't.

Comment on lines -94 to -98
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0o700
}
Copy link
Member

Choose a reason for hiding this comment

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

If this is no longer needed, it should be noted in the commit message. I suspect it stems from the time we transitioned from a marker file to a marker directory?

Isn't the same logic needed for the content file then?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's based on a misunderstanding to begin with. The only thing these bits do on Windows is set the read only flag, which we don't do here. Having the defaults remove group & other write bits on unixes is best practice. I'll make a note of it.

@calmh calmh merged commit a2b8f23 into syncthing:main May 24, 2024
20 of 21 checks passed
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.

None yet

2 participants