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

Add error message when filename contains illegal characters for target storage #9395

Open
LantashTheTokra opened this issue Feb 2, 2024 · 18 comments · May be fixed by #9397
Open

Add error message when filename contains illegal characters for target storage #9395

LantashTheTokra opened this issue Feb 2, 2024 · 18 comments · May be fixed by #9397
Labels
enhancement New features or improvements of some kind, as opposed to a problem (bug) needs-triage New issues needed to be validated

Comments

@LantashTheTokra
Copy link

On Linux, ? and : are valid characters for filenames. On Android, they are not. As a result, the files cannot be written. My current setup: syncing files between my Linux laptop and Android phone. I tried to sync files that had :'s and ?'s in their names. The sync failed without giving useful error codes.

Current error messages:

In Linux web GUI
Screenshot from 2024-02-01 22-57-05
(just shows the sync hanging)

Android app
Screenshot_20240201-225712
(Error message: "Out of Sync")

Android web GUI

Screenshot_20240201-225727
(Error message: "syncing: finishing: opening temp file: open [PATH]/.syncthing.[FILENAME].tmp: operation not permitted"

Proposed warning: "Caution: Filenames contain characters that are not allowed on some operating systems."

@LantashTheTokra LantashTheTokra added enhancement New features or improvements of some kind, as opposed to a problem (bug) needs-triage New issues needed to be validated labels Feb 2, 2024
@rasa
Copy link
Member

rasa commented Feb 2, 2024

@LantashTheTokra Currently, Syncthing doesn't know why the files couldn't be written.

It could interrogate the disk partition to determine its format (ext4, NTFS, FAT, etc.), to see what characters are not allowed, but that would require a PR. The shirou/gopsutil package has this functionality.

Please note that #7876 would allow these files to be written on FAT formatted partitions, but would require all nodes to be running with this PR.

@tomasz1986
Copy link
Contributor

It could interrogate the disk partition to determine its format (ext4, NTFS, FAT, etc.), to see what characters are not allowed, but that would require a PR. The shirou/gopsutil package has this functionality.

Operating systems like Windows and Android (see https://stackoverflow.com/a/64021421) don't allow some characters regardless of the file system, so I don't think simply basing this on the file system alone will work. Syncthing currently uses a hard-coded list of invalid characters and names for Windows, displaying an error message when it encounters them. The same could probably be done for Android on the basis on the character list from the Android source code linked to in the StackOverflow answer.

Just for the record, even though the code is named isValidFatFilenameChar, from my testing under Android 14 on Google Pixel 8, Android disallows using them on the internal storage even if the actual file system is ext4.

@AudriusButkevicius
Copy link
Member

The shirou/gopsutil package has this functionality.

This is not reliable, esp on android which actively lies to make applications think certain things are supported.
I don't think we can do much here.

@bt90
Copy link
Contributor

bt90 commented Feb 2, 2024

We have something in place for Windows AFAIK:

case build.IsWindows && fs.WindowsInvalidFilename(file.Name) != nil:

We could do the same for Android.

@tomasz1986
Copy link
Contributor

tomasz1986 commented Feb 2, 2024

We could do the same for Android.

One catch with Android is that the restrictions seem to only apply to user storage (both internal and external). For example, if you run Syncthing as root and sync files on the /data partition, then you can create file names with those characters.

@bt90
Copy link
Contributor

bt90 commented Feb 2, 2024

I'd rather care about the average user to be honest. Is it even common to have files with such a name there?

@LantashTheTokra
Copy link
Author

I'd rather care about the average user to be honest. Is it even common to have files with such a name there?

Colons are perfectly reasonable characters to use.

@LantashTheTokra
Copy link
Author

derp

@rasa
Copy link
Member

rasa commented Feb 3, 2024

Another thought is adding a folder setting to have when Syncthing starts up, to try to create a file for every non-POSIX character ([^/0-9A-Za-z._-]), and note any failures. Then when a file create fails containing any of those characters, we provide a more descriptive error message?

This would work even when Android lies about the filesystem.

@bt90
Copy link
Contributor

bt90 commented Feb 3, 2024

Colons are perfectly reasonable characters to use.

Yes, except on Android and Windows.

Another thought is adding a folder setting to have when Syncthing starts up, to try to create a file for every non-POSIX character ([^/0-9A-Za-z._-]), and note any failures. Then when a file create fails containing any of those characters, we provide a more descriptive error message?

non-ASCII filenames are common though. Having basic error handling behind a feature flag nullifies its purpose. If you're able to find that setting, you're less likely to run into the problem in the first place.

@LantashTheTokra
Copy link
Author

I found the issue because my laptop runs linux, and I wasted several hours diagnosing the problem because there was no error message about it.

@imsodin
Copy link
Member

imsodin commented Feb 3, 2024

An unintrusive option would be to have heuristics for detecting potentially invalid filenames after an errors occurs. Compared to trying to detect filename limitations and preventing the error, the worst case is that we have false positives/negatives on error messages.

@hobson42
Copy link

hobson42 commented Feb 3, 2024

I use syncthing with Obsidian, and I frequently want to have a filename that is a question.

I tried replacing ? with ?, and that sort-of works. Obsidian shows the ? in its index, but the note itself has the correct display, and syncthing appears to replicate it to Windows and Android.

tomasz1986 added a commit to tomasz1986/syncthing that referenced this issue Feb 3, 2024
)

Currently, Syncthing tries to sync files to Android devices with no
consideration for its filename restrictions (see [1]). This commit makes
it so that similarly to Windows, Syncthing relies on a hard-coded list
of characters which are invalid on Android and displays a specific error
message when user tries to sync a file with one of the characters in its
name.

[1] https://stackoverflow.com/a/64021421

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
tomasz1986 added a commit to tomasz1986/syncthing that referenced this issue Feb 3, 2024
)

Currently, Syncthing tries to sync files to Android devices with no
consideration for its filename restrictions (see [1]). This commit makes
it so that similarly to Windows, Syncthing relies on a hard-coded list
of characters which are invalid on Android and displays a specific error
message when user tries to sync a file with one of the characters in its
name.

[1] https://stackoverflow.com/a/64021421

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
@mdonz
Copy link

mdonz commented Feb 9, 2024

FWIW, just adding a recent experience with a bar I think it's called in the filename, a "|".

Syncing is set up between 5 devices: 1x Linux Ubuntu, 3x Android, 1x Lineage OS (older version). The devices where sync could handle filenames with such "|" character were Ubuntu, old LineageOS (ver. 15 = Android 8) and oldest Android (Nokia 7 Plus running Android 10).
The two newer Android devices (Motorola, Android 12) and Xiaomi, Android 13) could not sync until that character was removed or replaced in the filename.

@JanKanis
Copy link

I'm getting the same error when I try to sync files containing '?' or '"' to android. However on my phone these characters are allowed on the primary external storage I'm syncing to. So as a workaround, I first copied the files there manually (using fsync, preserving modification time), after that Syncthing recognized them and now says the folder is up to date. If I modify one of these files I'll probably have to manually copy it again, but most of my files don't use these characters.

On my phone primary external storage is actually internal, and backed by an ext4 filesystem. As far as I know such a setup is quite common for phones with sufficient internal storage. For such phones, Syncthing should just be able to write files containing '?' and other reserved chars.

@LearnedLately
Copy link

LearnedLately commented May 1, 2024

Could syncthing on Android simply check the out of sync filenames for problematic characters like :"? and display a more helpful error message then? It only matters when they fail to sync properly.

@JanKanis
Copy link

JanKanis commented May 1, 2024

Yes, I think. Having a better error message is the point of this issue.

@Neyl-123
Copy link

Neyl-123 commented May 2, 2024

I had some files making trouble going from Linux to Android 12 (MIUI 13). After some investigation I found that ":?| and sometimes # depending on whats after it (which apparently wasn't mentioned before in this thread), don't work on the Android side. So if a error occurs and these characters are part of the filename, a simple "Hey, maybe Android is refusing to work because of these characters" or something like that would be a pragmatic and fairly simple improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features or improvements of some kind, as opposed to a problem (bug) needs-triage New issues needed to be validated
Projects
None yet
Development

Successfully merging a pull request may close this issue.