Skip to content

Commit 5f85b6a

Browse files
authored
Merge pull request #23 from richardleach/hydahy/shortpathtests2
Skip tests that rely upon short names if these are unavailable.
2 parents 7746dcd + 52ef25c commit 5f85b6a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Win32.pm

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,4 +1423,37 @@ DllUnregisterServer.
14231423
14241424
=back
14251425
1426+
=head1 CAVEATS
1427+
1428+
=head2 Short Path Names
1429+
1430+
There are many situations in which modern Windows systems will not have
1431+
the L<short path name|https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#short-vs-long-names>
1432+
(also called 8.3 or MS-DOS) alias for long file names available.
1433+
1434+
Short path support can be configured system-wide via the registry,
1435+
but the default on modern systems is to configure short path usage per
1436+
volume. The configuration for a volume can be queried in a number of ways,
1437+
but these may either be unreliable or require elevated (administrator)
1438+
privileges.
1439+
1440+
Typically, the configuration for a volume can be queried using the C<fsutil>
1441+
utility, e.g. C<fsutil 8dot3name query d:>. On the C level, it can be queried
1442+
with a C<FSCTL_QUERY_PERSISTENT_VOLUME_STATE> request to the
1443+
C<DeviceIOControl> API call, as described in
1444+
L<this article|https://www.codeproject.com/Articles/304374/Query-Volume-Setting-for-State-Windows>.
1445+
However, both of these methods require administrator privileges to work.
1446+
1447+
The Win32 module does not perform any per-volume check and simply fetches
1448+
short path names in the same manner as the underlying Windows API call it
1449+
uses: If short path names are disabled, the call will still succeed but the
1450+
long name will actually be returned.
1451+
1452+
Note that on volumes where this happens, C<GetANSIPathName> usually cannot be
1453+
used to return useful filenames for files that contain unicode characters.
1454+
(In code page 65001, this may still work.) Handling unicode filenames in this
1455+
legacy manner relies upon C<GetShortPathName> returning 8.3 filenames, but
1456+
without short name support, it will return the filename with all unicode
1457+
characters replaced by question mark characters.
1458+
14261459
=cut

t/GetShortPathName.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ use strict;
22
use Test;
33
use Win32;
44

5+
BEGIN {
6+
Win32::CreateFile("8dot3test_canary_GetShortPathName $$");
7+
my $canary = Win32::GetShortPathName("8dot3test_canary_GetShortPathName $$");
8+
unlink("8dot3test_canary_GetShortPathName $$");
9+
if ( length $canary > 12 ) {
10+
print "1..0 # Skip: The system and/or current volume is not configured to support short names.\n";
11+
exit 0;
12+
}
13+
}
14+
515
my $path = "Long Path $$";
616
unlink($path);
717
END { unlink $path }

t/Unicode.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ BEGIN {
1818
print "1..0 # Skip: Unicode support requires Windows 2000 or later\n";
1919
exit 0;
2020
}
21+
Win32::CreateFile("8dot3test_canary_Unicode $$");
22+
my $canary = Win32::GetShortPathName("8dot3test_canary_Unicode $$");
23+
unlink("8dot3test_canary_Unicode $$");
24+
if ( length $canary > 12 ) {
25+
print "1..0 # Skip: The system and/or current volume is not configured to support short names.\n";
26+
exit 0;
27+
}
2128
}
2229

2330
my $home = Win32::GetCwd();

0 commit comments

Comments
 (0)