Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
i3-dmenu-desktop: Manually search for topdir (#4033)
Browse files Browse the repository at this point in the history
Since 3a672bc, using follow or follow_fast, does not set
$File::Find::topdir, breaking our deduplication.

Fixes #4031
  • Loading branch information
orestisfl committed Oct 18, 2020
1 parent 440268f commit 71c059d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions i3-dmenu-desktop
Expand Up @@ -13,6 +13,7 @@ use POSIX qw(locale_h);
use File::Find;
use File::Basename qw(basename);
use File::Temp qw(tempfile);
use List::Util 'first';
use Getopt::Long;
use Pod::Usage;
use v5.10;
Expand Down Expand Up @@ -123,6 +124,8 @@ for my $dir (split(':', $xdg_data_dirs)) {
# Cleanup the paths, maybe some application does not cope with double slashes
# (the field code %k is replaced with the .desktop file location).
@searchdirs = map { s,//,/,g; $_ } @searchdirs;
# Also remove any trailing slashes.
@searchdirs = map { s,/*$,,g; $_ } @searchdirs;

# To avoid errors by File::Find’s find(), only pass existing directories.
@searchdirs = grep { -d $_ } @searchdirs;
Expand All @@ -133,8 +136,15 @@ find(
return unless substr($_, -1 * length('.desktop')) eq '.desktop';
my $relative = $File::Find::name;

# + 1 for the trailing /, which is missing in ::topdir.
substr($relative, 0, length($File::Find::topdir) + 1) = '';
# Find and then replace the directory in @searchdirs in which the
# current file is located. We used to do this with
# $File::Find::topdir but it is not supported when using the
# 'follow' or 'follow_fast' options.
# See #3973, #4031.
my $topdir = first { substr($relative, 0, length($_)) eq $_ } @searchdirs;

# + 1 for the trailing /, which is missing in $topdir.
substr($relative, 0, length($topdir) + 1) = '';

# Don’t overwrite files with the same relative path, we search in
# descending order of importance.
Expand Down

0 comments on commit 71c059d

Please sign in to comment.