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

Fix VFX Windows .lnk files freeze/crash issue #3057

Merged
merged 8 commits into from
Apr 7, 2021

Conversation

allexzander
Copy link
Contributor

@allexzander allexzander commented Apr 1, 2021

This is a fix for #3041

As mentioned here https://doc.qt.io/qt-5/qfileinfo.html#details

"On Windows, shortcuts (.lnk files) are currently treated as symlinks. As on Unix systems, the property getters return the size of the targeted file, not the .lnk file itself. This behavior is deprecated and will likely be removed in a future version of Qt, after which .lnk files will be treated as regular files."

  • In our case, executing any of QFileInfo or QDir functions that query the ".lnk" file internally, would result in a freeze if the ".lnk" is not pointing to a valid location (a shortcut created on another PC to a folder that only exists there). The freeze is causing the CfAPI to trigger the hydration, even though, it's not triggered by the desktop client's logic (not sure why this happens).
  • Another problem is - when clicking "Free up local space" the logic breaks when trying to create a placeholder for a ".lnk" file because the ".lnk" file is queried with QFileInfo::isDir() which does not lead to a freeze, but, the result returned is incorrect (it treats this file as a directory, while it should be treated as a normal file. This is caused by the same Qt's bug described above). The result - is a crash because of using an incorrect file handle for placeholder creation.

During the discussion with teammates, we've decided to always ignore ".lnk" files on Windows. With, or without the VFS enabled (for consistency). ".lnk" files point to a real file/folder anyways, so, by ignoring them from sync, we are not losing the data.

@allexzander allexzander changed the title Bugfix/vfs windows lnk files freeze issue Fix VFX Windows .lnk files freeze/crash issue Apr 1, 2021
src/libsync/discovery.cpp Outdated Show resolved Hide resolved
src/libsync/discoveryphase.cpp Outdated Show resolved Hide resolved
const bool isServerEntrySymLink = !e.localEntry.isValid() && e.serverEntry.isValid() && !e.serverEntry.isDirectory && FileSystem::isLnkFile(e.serverEntry.name);
#else
const bool isServerEntrySymLink = false;
#endif
Copy link

Choose a reason for hiding this comment

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

I wonder if it is a good idea to move the preprocessor conditionals into the FileSystem::isLnkFile() method? That would simplify the logic a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FlexW
In this case, I wouldn't do that, cause, "isLnkFile" can be used on other platforms too.

@allexzander allexzander force-pushed the bugfix/vfs-windows-lnk-files-freeze-issue branch from 4ff8ce0 to d37c28f Compare April 5, 2021 11:06
@cscholz
Copy link

cscholz commented Apr 5, 2021

@allexzander: Let me known when the fix is available in the daily build. I'm gonne test once it again.

@er-vin
Copy link
Member

er-vin commented Apr 6, 2021

* In our case, executing any of **QFileInfo** or **QDir** functions that query the ".lnk" file internally, would result in a freeze if the ".lnk" is not pointing to a valid location (a shortcut created on another PC to a folder that only exists there). The freeze is causing the CfAPI to trigger the hydration, even though, it's not triggered by the desktop client's logic (not sure why this happens).

This is because a QFileInfo or a QDir call will need to read the content of the lnk file to know where it points to in order to give a proper reply. Which will thus trigger the implicit hydration code path in a secondary thread (Windows is triggering this, implicit hydration is generally triggered by outside processes but not in that case). Now remember the download itself has to be done in the main thread, but the main thread is blocked waiting on a QFileInfo or a QDir sync call so it's not able to process the necessary events.

Copy link
Member

@er-vin er-vin left a comment

Choose a reason for hiding this comment

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

As for the general approach, a word of caution: are we sure this is unused by users? I wouldn't be surprised if there were people somewhere having symlinks or lnk files pointing inside or outside the sync folder.

I'm not saying it shouldn't be changed (especially pointing outside is... well... don't :-)), but clearly it should be done with some care to not silently break something for those users.

@@ -305,7 +306,13 @@ void DiscoverySingleLocalDirectoryJob::run() {
i.inode = dirent->inode;
i.isDirectory = dirent->type == ItemTypeDirectory;
i.isHidden = dirent->is_hidden;
i.isSymLink = dirent->type == ItemTypeSoftLink;
#ifdef Q_OS_WIN
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't that one done in csync_vio_local_win.cpp instead? With what you're trying to achieve, this would be a more natural fit to me to not set ItemTypeSoftLink there in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@er-vin In fact, I am fine with ItemTypeSoftLink, but, I've moved this into csync_vio_local_win.cpp indeed. Pushed a new commit with changes.

@allexzander
Copy link
Contributor Author

As for the general approach, a word of caution: are we sure this is unused by users? I wouldn't be surprised if there were people somewhere having symlinks or lnk files pointing inside or outside the sync folder.

I'm not saying it shouldn't be changed (especially pointing outside is... well... don't :-)), but clearly it should be done with some care to not silently break something for those users.

@er-vin We've been discussing that. And, yes, indeed, this can be used by some people. More on that, some of them may be using SMB share and have links pointing to a file/folder on their SMB file server machine. Having said that, right now, the problem with VFS is much more severe than it will become for those users, and, we can think of some improvement for them later if they start to complain. It's the simplest way right now to just ignore those files.

Other solutions:

  • Create a wrapper around QFileInfo/QDir/QFile, and use it in place of a direct call to these classes' methods, but, treat ".lnk" files in a special way (e.g. use WinaAPI functions like PathIsDirectory that don't freeze on ".lnk" files from what I have found out). This requires lots of changes in multiple places (not just CfAPI code, but, also owncloudpropagator.cpp has some calls that freeze, and, possibly, other places.
  • Make those files (.lnk ones) always local and don't allow dehydration (this works too from what I've noticed). But, this introduces changes to the VFS logic. This is not something for 3.2.0, I'd say, as, this will need to be tested.

So, once again, ignoring those ".lnk" files, for now, is really a quick fix for 3.2.0.

@allexzander allexzander requested review from er-vin and FlexW April 6, 2021 07:51
@er-vin
Copy link
Member

er-vin commented Apr 6, 2021

So, once again, ignoring those ".lnk" files, for now, is really a quick fix for 3.2.0.

Not denying that, I'm not even saying this should move in a different direction it's likely the better approach. I'm just wondering about the impact for the users who already have those lnk files synced typically. Will that make them disappear? Only locally or also remotely?

I'm just wondering if you want a notification on top like the warning @FlexW has been working on. So that they know what to expect.

Also: this could be a fix for 3.2.1... it's really last minute again.

@allexzander
Copy link
Contributor Author

allexzander commented Apr 6, 2021

So, once again, ignoring those ".lnk" files, for now, is really a quick fix for 3.2.0.

Not denying that, I'm not even saying this should move in a different direction it's likely the better approach. I'm just wondering about the impact for the users who already have those lnk files synced typically. Will that make them disappear? Only locally or also remotely?

I'm just wondering if you want a notification on top like the warning @FlexW has been working on. So that they know what to expect.

Also: this could be a fix for 3.2.1... it's really last minute again.

@er-vin Remote ".lnk" files will not disappear. They are just ignored locally and remotely altogether. Users can't sync new ".lnk" files from the remote, even if those were being synced before. Also, newly created ".lnk" files won't get uploaded to the remote anymore.

There is a notification message already (files from ignore list as well as symbolic links are not synced, or something like that).

This MUST be in 3.2.0 as this is a severe issue and it will look like 3.2.0 is completely broken for new users. So, we've decided it should be in 3.2.0, otherwise, we need RC4, which we can not afford. We will be testing daily build with this fix and release 3.2.0. Without this, VFS is pretty-much useless :(

@er-vin
Copy link
Member

er-vin commented Apr 6, 2021

There is a notification message already (files from ignore list as well as symbolic links are not synced, or something like that).

Ah then it's all good I guess.

This MUST be in 3.2.0 as this is a severe issue and it will look like 3.2.0 is completely broken for new users.

If they have a .lnk file in there but yes. I wonder if that's really that common.

So, we've decided it should be in 3.2.0, otherwise, we need RC4, which we can not afford. We will be testing daily build with this fix and release 3.2.0. Without this, VFS is pretty-much useless :(

Again: if you have a .lnk file in your sync folder.

In any case the "this could be for 3.2.1" was more for the notification but it's already there anyway.

@allexzander
Copy link
Contributor Author

Again: if you have a .lnk file in your sync folder.

@er-vin It's not for 50% of users I guess, but, for many of them. cloud.nextcloud.com, for example, has a few of those files, same with those users that commented on the issue I've mentioned - they both had .lnk files in their sync folder. So, it's kinda, big enough amount of users that will start to complain after they upgrade to 3.2.0 and enable VFS.

Sor, there are risks in both cases, I am not even sure now what's worse.

@tomdereub
Copy link
Contributor

For me, ignoring .ink files is a good fix for now. I have .ink files in my folders, so I can't use vfx for the moment.
And generaly .ink files are not usable over synchronization anyway: users often synchronize their files in C:\users\name\nextcloud, file paths are different, so a .ink is usable just by one user.
From my point of view, it's much worst to get many people with a big error than to just not synchronize shortcuts.

@er-vin
Copy link
Member

er-vin commented Apr 7, 2021

Again: if you have a .lnk file in your sync folder.

@er-vin It's not for 50% of users I guess, but, for many of them. cloud.nextcloud.com, for example, has a few of those files, same with those users that commented on the issue I've mentioned - they both had .lnk files in their sync folder. So, it's kinda, big enough amount of users that will start to complain after they upgrade to 3.2.0 and enable VFS.

Yeah that's what I was trying to gauge, are we talking say about 5% or 50%. But again, if it doesn't kill preexisting files on the server and locally and if there's a notification it's probably good. From your assessment it seems to have both so it's probably the right approach and won't require further work.

Sor, there are risks in both cases, I am not even sure now what's worse.

Welcome in the wonderful world of dealing with people data. ;-)

@@ -177,9 +178,15 @@ void ProcessDirectoryJob::process()
// local stat function.
// Recall file shall not be ignored (#4420)
bool isHidden = e.localEntry.isHidden || (f.first[0] == '.' && f.first != QLatin1String(".sys.admin#recall#"));
#ifdef Q_OS_WIN
// exclude ".lnk" files as they are not essential, but, causing troubles when enabling the VFS due to QFileInfo::isDir() and other methods are freezing, which causes the ".lnk" files to start hydrating and freezing the app eventually.
const bool isServerEntrySymLink = !e.localEntry.isValid() && e.serverEntry.isValid() && !e.serverEntry.isDirectory && FileSystem::isLnkFile(e.serverEntry.name);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe s/SymLink/LnkFile/ here? (and in the else part of course) or s/SymLink/WindowsShortcut/ as you did in the vfs implementation. Just to align the naming everywhere, since it's not a symlink in the unix sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@er-vin Changed

@allexzander allexzander requested a review from er-vin April 7, 2021 07:42
@nextcloud-desktop-bot
Copy link

AppImage file: Nextcloud-PR-3057-e76d9100bc6293ea3a5b4698aee882572edf8271-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@FlexW
Copy link

FlexW commented Apr 7, 2021

What I don't like is that we now have this isLnkFile() method and a special case just for these files. In my opinion we should have just one, for example isSymLink() method, that handles lnk files as well as symbolic links on other platforms, so that we don't sprinkle our code ifndef's. But I guess that is to much work for now :)

@er-vin
Copy link
Member

er-vin commented Apr 7, 2021 via email

@allexzander
Copy link
Contributor Author

/rebase

Signed-off-by: allexzander <blackslayer4@gmail.com>
Signed-off-by: allexzander <blackslayer4@gmail.com>
Signed-off-by: allexzander <blackslayer4@gmail.com>
… placeholder.

Signed-off-by: allexzander <blackslayer4@gmail.com>
@allexzander allexzander merged commit 5eb6834 into master Apr 7, 2021
@allexzander allexzander deleted the bugfix/vfs-windows-lnk-files-freeze-issue branch April 7, 2021 09:28
@er-vin
Copy link
Member

er-vin commented Apr 7, 2021 via email

@allexzander
Copy link
Contributor Author

@er-vin Daammn. Yeah. This is what happens when trying to do some work while being on a call as well :( Do you think I should rebase master? Or let it slide this time?

@er-vin
Copy link
Member

er-vin commented Apr 7, 2021 via email

@vgdh
Copy link

vgdh commented Jul 3, 2021

I also want sync *.lnc files!

@wlnx
Copy link

wlnx commented Jul 5, 2021

Well... This change breaks things. Windows has symlinks, and lnk-files are not symlinks at all. The files are closer to *.desktop files in some Linux-DEs. The way how Qt works with the files is an issue and should be handled in a proper way, because just ignoring lnk-files is a good way to break user filesets (e. g., Total Commander portable contains multiple WebSite.lnk files) and workflows (e. g., syncdir may contain something like hr-docs.lnk... Ok, may have contained xD).
Could you pls make the point optional with something like "you can have either lnk-files or vfs"? Pleeeaaazzz...

@clayauld
Copy link

clayauld commented Jul 22, 2021

I think this issue and the "fix" posted here is a complete regression for Windows users. I understand the issue of not syncing symlinks, but .lnk files in windows are not that. They are shortcuts. The default behavior (in my opinion) should be to ignore the .lnk files in VFS mode, but put them as part of the ignore list instead of hard-coding it. Then, a user can remove them from the ignore list and disable VFS mode if they want to sync those files. OR the files can be treated like .desktop files in Linux.

Because this is hardcoded, I'm seriously thinking about forking the repo and removing this "fix" so I can use the .lnk files like I used to. Otherwise I'll be switching to a completely different software entirely.....

For now I've downgraded my client to v3.2.0-rc3

@allexzander
Copy link
Contributor Author

I can understand you, but, right now, it's something we had to do to allow VFS to work. At some point (could be even this year), we plan to approach this problem from another perspective and bring back .lnk files synchronization.

@clayauld
Copy link

Fair enough. I'm not a user of the VFS mode so until that change occurs I'll use my forked version.

I'll keep an eye on the development effort, in any case.

@vgdh
Copy link

vgdh commented Jul 23, 2021

lnk must back! ))

@dbmaxpayne
Copy link

Hey, I'd also like to have *.lnk-syncing back. I second the suggestion to implement an entry in the global ignore list that only gets set when VFS is used and then cannot be deselected. However, I'm also using the full sync and am missing my *.lnk files.

@clayauld
Copy link

I've moved back over to Seafile because of these issues. Its a breaking change for me and really limits my ability to use Nextcloud as I would like.

@wlnx
Copy link

wlnx commented Jul 27, 2021

I've moved back over to Seafile because of these issues. Its a breaking change for me and really limits my ability to use Nextcloud as I would like.

Well... Actually, I installed NC Desktop 3.1.3, thus ends. VFS not working, but it seems to me to be a cosmetic feature. I'd better miss some hard drive space rather than some sensitive data.

@Taomyn
Copy link

Taomyn commented Aug 5, 2021

Not sync'ing .lnk files is a huge mistake, users with shortcuts on their desktops would completely lose them if they were to recover their local profile for any reason and not everyone can remember exactly what they were to simply "put them back manually".

@allexzander
Copy link
Contributor Author

@Taomyn Desktop client is not meant for using it as backup software.

@Taomyn
Copy link

Taomyn commented Aug 5, 2021

@Taomyn Desktop client is not meant for using it as backup software.

Show me exactly where I wrote it was - irrelevant

@allexzander
Copy link
Contributor Author

@Taomyn

users with shortcuts on their desktops would completely lose them if they were to recover their local profile

Recover assumes having a backup that one wants to recover. Did you mean something else? When you connect the Nextcloud Desktop client to a remote directory, a local directory is not set to Desktop by default, unless you choose it manually. Local sync directory is a separate folder not related to Desktop, Downloads, Documents, etc. Hard to think of any use case where .lnk files on a Desktop synced to a remote server would be useful.

In any case, until we move to Qt 6.2+, we won't be working on fixing .lnk files with VFS as we have a lot of work to do in more critical areas. Apologies for temporary inconvenience.

@Taomyn
Copy link

Taomyn commented Aug 5, 2021

@Taomyn
Recover assumes having a backup that one wants to recover. Did you mean something else? When you connect the Nextcloud

Well you know what they say about assumption - taking a file out of the recycle bin and back onto the desktop can also be seen as recover, same for emails from Deleted Items in Outlook.

No end of users store documents on their desktop, yes, it's not the best or even correct place, but it still happens and won't stop happening - adding the Desktop folder is a must to allow them to sync those files as well. I think you need to "think" harder.

I'm just glad that the other users I need to support are using OneDrive, as its "Files-on-demand" feature has zero issues with this plus Desktop is an included folder by default. It too isn't a backup solution.

@allexzander
Copy link
Contributor Author

@Taomyn

I think you need to "think" harder.

I don't really agree this is a good place for such conversations. I understand your frustration, but, there is little I can do right now.

If by any chance, you can find some spare time, we would welcome it if you open a PR that brings back .lnk files support that is fully compatible with CFApi and Qt.

@vgdh
Copy link

vgdh commented Aug 5, 2021

😥

@wlnx
Copy link

wlnx commented Aug 9, 2021

@Taomyn Desktop client is not meant for using it as backup software.

@allexzander It definitely isn't. But is it meant for using it as synchronization software when it isn't synchronizing files?

As for the general approach, a word of caution: are we sure this is unused by users? I wouldn't be surprised if there were people somewhere having symlinks or lnk files pointing inside or outside the sync folder.
I'm not saying it shouldn't be changed (especially pointing outside is... well... don't :-)), but clearly it should be done with some care to not silently break something for those users.

@er-vin We've been discussing that. And, yes, indeed, this can be used by some people. More on that, some of them may be using SMB share and have links pointing to a file/folder on their SMB file server machine. Having said that, right now, the problem with VFS is much more severe than it will become for those users, and, we can think of some improvement for them later if they start to complain. It's the simplest way right now to just ignore those files.

Other solutions:

  • Create a wrapper around QFileInfo/QDir/QFile, and use it in place of a direct call to these classes' methods, but, treat ".lnk" files in a special way (e.g. use WinaAPI functions like PathIsDirectory that don't freeze on ".lnk" files from what I have found out). This requires lots of changes in multiple places (not just CfAPI code, but, also owncloudpropagator.cpp has some calls that freeze, and, possibly, other places.
  • Make those files (.lnk ones) always local and don't allow dehydration (this works too from what I've noticed). But, this introduces changes to the VFS logic. This is not something for 3.2.0, I'd say, as, this will need to be tested.

So, once again, ignoring those ".lnk" files, for now, is really a quick fix for 3.2.0.

We started to complain. 😊Moreover, you knew that we would. Unfortunately, I ain't a programmer and cannot write the patch for lnk+CFapi+Qt to work together. That's why the only thing I can do is whining: "Please fix the regression".

@CombeeMike
Copy link

CombeeMike commented Aug 27, 2021

I'm also one of those who really miss syncing of windows *.lnk files and for whom this change drastically degrades the usefulness of my whole Nextcloud installation.

Most of my thoughts have already been said by someone else, so I won't be repeating them here. However, I'd like to explain my use case here since that's maybe something you (the devs) would like to consider for future changes etc.:

Here's my use case (copied form here)

I regularly work on multiple machines (work notebook, desktop pc home, notebook home, ...) which all "share" some basic data (data synced via Nextcloud, data synced via one drive, data "synced" via GitHub, ...).

For all of this data I built an extensive list of "most valuable links" which is basically just a folder inside my Nextcloud holding links to important folders, files, programs, ...

I can access all those links very quickly using a quick launcher like Launchy and/or PowerToys Run.

Most of those links "internally" use a set of defined system vars in their paths instead of absolute paths to support different paths on different machines. E.g.: The Nextcloud.lnk points to %nextcloud% instead of D:\Nextcloud which allows the path to differ on every machine.

@SilenyKrecek
Copy link

+1 to CombeeMike
My use case is quite similar to his.
.lnk must come back :D

@mgallien mgallien added this to the 3.4.0 milestone Oct 19, 2021
chylex added a commit to chylex/Nextcloud-Desktop that referenced this pull request Feb 7, 2022
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