Skip to content
This repository was archived by the owner on Jan 14, 2018. It is now read-only.

Commit 18ba503

Browse files
committed
Fixed some Linux stuff
1 parent 680aa8a commit 18ba503

File tree

2 files changed

+59
-57
lines changed

2 files changed

+59
-57
lines changed

src/dfile.d

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,69 +1869,71 @@ version (Windows) {
18691869
/// Report a symbolic link.
18701870
void report_link()
18711871
{
1872-
report("Soft symbolic link");
1873-
1872+
enum LINK = "Soft symbolic link";
18741873
version (Windows)
1875-
{ // Works half the time, see the Wiki post.
1876-
version (Symlink)
1877-
{
1878-
HANDLE hFile;
1879-
DWORD returnedLength;
1880-
WIN32_SYMLINK_REPARSE_DATA_BUFFER buffer;
1881-
1882-
const char* p = &linkname[0];
1883-
SECURITY_ATTRIBUTES* sa; // Default
1884-
1885-
hFile = CreateFileA(p, GENERIC_READ, 0u,
1886-
sa, OPEN_EXISTING,
1887-
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, cast(void*)0);
1888-
if (hFile == INVALID_HANDLE_VALUE) { //TODO: Check why LDC2 fails here.
1889-
/* Error creating directory */
1890-
/* TclWinConvertError(GetLastError()); */
1891-
return;
1892-
}
1893-
/* Get the link */
1894-
if (!DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, NULL, 0, &buffer,
1895-
WIN32_SYMLINK_REPARSE_DATA_BUFFER.sizeof, &returnedLength, NULL)) {
1896-
/* Error setting junction */
1874+
{
1875+
report(LINK);
1876+
// Works half the time, see the Wiki post.
1877+
version (Symlink)
1878+
{
1879+
HANDLE hFile;
1880+
DWORD returnedLength;
1881+
WIN32_SYMLINK_REPARSE_DATA_BUFFER buffer;
1882+
1883+
const char* p = &linkname[0];
1884+
SECURITY_ATTRIBUTES* sa; // Default
1885+
1886+
hFile = CreateFileA(p, GENERIC_READ, 0u,
1887+
sa, OPEN_EXISTING,
1888+
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, cast(void*)0);
1889+
if (hFile == INVALID_HANDLE_VALUE) { //TODO: Check why LDC2 fails here.
1890+
/* Error creating directory */
18971891
/* TclWinConvertError(GetLastError()); */
1898-
CloseHandle(hFile);
18991892
return;
19001893
}
1894+
/* Get the link */
1895+
if (!DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, NULL, 0, &buffer,
1896+
WIN32_SYMLINK_REPARSE_DATA_BUFFER.sizeof, &returnedLength, NULL)) {
1897+
/* Error setting junction */
1898+
/* TclWinConvertError(GetLastError()); */
1899+
CloseHandle(hFile);
1900+
return;
1901+
}
19011902

1902-
CloseHandle(hFile);
1903+
CloseHandle(hFile);
19031904

1904-
if (!IsReparseTagValid(buffer.ReparseTag)) {
1905-
/* Tcl_SetErrno(EINVAL); */
1906-
return;
1907-
}
1905+
if (!IsReparseTagValid(buffer.ReparseTag)) {
1906+
/* Tcl_SetErrno(EINVAL); */
1907+
return;
1908+
}
19081909

1909-
DWORD wstrlen(const(void)* p) {
1910-
DWORD s;
1911-
wchar* wp = cast(wchar*)p;
1912-
while (*wp++ != wchar.init) ++s;
1913-
return s;
1914-
}
1910+
DWORD wstrlen(const(void)* p) {
1911+
DWORD s;
1912+
wchar* wp = cast(wchar*)p;
1913+
while (*wp++ != wchar.init) ++s;
1914+
return s;
1915+
}
19151916

1916-
printf(" to ");
1917-
stdout.flush; // on x86-dmd builds, used to move cursor
1918-
const(void)* wp = &buffer.ReparseTarget[2];
1919-
DWORD c;
1920-
WriteConsoleW(
1921-
GetStdHandle(STD_OUTPUT_HANDLE),
1922-
wp,
1923-
wstrlen(wp) / 2,
1924-
&c,
1925-
cast(void*)0
1926-
);
1927-
} // version (Symlink)
1917+
printf(" to ");
1918+
stdout.flush; // on x86-dmd builds, used to move cursor
1919+
const(void)* wp = &buffer.ReparseTarget[2];
1920+
DWORD c;
1921+
WriteConsoleW(
1922+
GetStdHandle(STD_OUTPUT_HANDLE),
1923+
wp,
1924+
wstrlen(wp) / 2,
1925+
&c,
1926+
cast(void*)0
1927+
);
1928+
} // version (Symlink)
19281929
} // version (Windows)
19291930
version (Posix)
19301931
{
19311932
import core.stdc.stdio : printf;
19321933
import core.sys.posix.stdlib : realpath;
1933-
char* p = realpath(&linkname[0], cast(char*)0);
1934-
if (p) printf(" to %s", p);
1934+
report(LINK, false);
1935+
char* p = realpath(&filename[0], cast(char*)0);
1936+
if (p) printf(" to %s\n", p);
19351937
}
19361938
}
19371939

src/main.d

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void prescan(string path, bool cont)
115115
version (Posix) {
116116
import core.sys.posix.sys.stat :
117117
S_IFBLK, S_IFCHR, S_IFIFO, S_IFREG, S_IFDIR, S_IFLNK, S_IFSOCK, S_IFMT;
118-
if ((a & S_IFMT) == S_IFLNK)
118+
if (a & S_IFLNK)
119119
if (cont)
120120
goto FILE;
121121
else
@@ -134,16 +134,16 @@ FILE:
134134
debug dbg("Closing file...");
135135
fclose(fp);
136136
}
137-
else if (a & S_IFBLK)
138-
reportfile("Block", filename);
139137
else if (a & S_IFCHR)
140-
reportfile("Character special", filename);
138+
report("Character special");
139+
else if (a & S_IFBLK)
140+
report("Block");
141141
else if (a & S_IFSOCK)
142-
reportfile("Socket", filename);
142+
report("Socket");
143143
else if (a & S_IFDIR)
144-
reportfile("Directory", filename);
144+
report("Directory");
145145
else
146-
report_unknown(filename);
146+
report_unknown;
147147
} else version (Windows) { // Windows
148148
import core.sys.windows.winnt :
149149
FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_REPARSE_POINT;

0 commit comments

Comments
 (0)