FilenCloudDienste / filen-desktop-legacy

Desktop client for filen.io
https://filen.io
GNU Affero General Public License v3.0
3 stars 1 forks source link

Fix directory detection in .filenignore #271

Open szapp opened 7 months ago

szapp commented 7 months ago

Due to a usage limitation in @gerhobbelt/gitignore-parser, directory patterns with a trailing slash in the .filenignore do not work as expected. This PR fixes this issue.

Details

The .gitignore syntax utilized for the .filenignore syntax supports three different ways of excluding directories.

  1. /dir will match a file, directory, link, anything named dir
  2. /dir/ will match only a directory named dir
  3. /dir/* will match all files, directories and anything else inside a directory named dir (but not the dir directory itself).

Source: https://stackoverflow.com/questions/17888695/#answer-38559600

The second item of the list above is not currently supported by Filen, resulting in the directory /dir/ to still be uploaded. This happens, because @gerhobbelt/gitignore-parser cannot deduce whether a path is a directory or file when matching it against the pattern. The proposed solution is to append directory paths with a trailing slash, see https://www.npmjs.com/package/@gerhobbelt/gitignore-parser#notes

Implementation

Here, I have sought out (I believe) all usages of @gerhobbelt/gitignore-parser and before passing a path to the denies method, added a trailing slash, if the path is a directory.

I tested the changes locally and found the changes to have the desired effects. Nevertheless, I encourage formal testing as I could not find a testsuite and only build and tested the application on windows. I welcome suggestions for edits.