diff options
author | Ron Yorston <rmy@pobox.com> | 2019-01-05 14:16:50 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-01-05 14:16:50 +0000 |
commit | fa96aa8d70eb1dfd7b3550fab417a43b3a507a6d (patch) | |
tree | 2b7d4c0a4a56175018f28e7e116a3dcdfb78e06a /win32 | |
parent | da7d205446459dfa1ba7bb46206955383dc6a420 (diff) | |
download | busybox-w32-fa96aa8d70eb1dfd7b3550fab417a43b3a507a6d.tar.gz busybox-w32-fa96aa8d70eb1dfd7b3550fab417a43b3a507a6d.tar.bz2 busybox-w32-fa96aa8d70eb1dfd7b3550fab417a43b3a507a6d.zip |
busybox: add --uninstall option
Add an option to allow hard links to be removed.
busybox --uninstall file
removes all hard links to the given file (including the file itself.)
Since Microsoft Windows refuses to delete a running executable a
BusyBox binary is unable to remove links to itself.
busybox --uninstall -n file
displays the names of all hard links to the given file.
Although this feature is couched in terms of uninstalling BusyBox
it's actually quite general: it can be used to delete or display
hard links to any file.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index c420992d5..8d1da5199 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1289,3 +1289,42 @@ ULONGLONG CompatGetTickCount64(void) | |||
1289 | return GetTickCount64(); | 1289 | return GetTickCount64(); |
1290 | } | 1290 | } |
1291 | #endif | 1291 | #endif |
1292 | |||
1293 | #if ENABLE_FEATURE_INSTALLER | ||
1294 | /* | ||
1295 | * Enumerate the names of all hard links to a file. The first call | ||
1296 | * provides the file name as the first argument; subsequent calls must | ||
1297 | * set the first argument to NULL. Returns 0 on error or when there are | ||
1298 | * no more links. | ||
1299 | */ | ||
1300 | int enumerate_links(const char *file, char *name) | ||
1301 | { | ||
1302 | static HANDLE h = INVALID_HANDLE_VALUE; | ||
1303 | char aname[PATH_MAX]; | ||
1304 | wchar_t wname[PATH_MAX]; | ||
1305 | DWORD length = PATH_MAX; | ||
1306 | DECLARE_PROC_ADDR(HANDLE, FindFirstFileNameW, LPCWSTR, DWORD, LPDWORD, | ||
1307 | PWSTR); | ||
1308 | DECLARE_PROC_ADDR(BOOL, FindNextFileNameW, HANDLE, LPDWORD, PWSTR); | ||
1309 | |||
1310 | if (!INIT_PROC_ADDR(kernel32.dll, FindFirstFileNameW) || | ||
1311 | !INIT_PROC_ADDR(kernel32.dll, FindNextFileNameW)) | ||
1312 | return 0; | ||
1313 | |||
1314 | if (file != NULL) { | ||
1315 | wchar_t wfile[PATH_MAX]; | ||
1316 | MultiByteToWideChar(CP_ACP, 0, file, -1, wfile, PATH_MAX); | ||
1317 | h = FindFirstFileNameW(wfile, 0, &length, wname); | ||
1318 | if (h == INVALID_HANDLE_VALUE) | ||
1319 | return 0; | ||
1320 | } | ||
1321 | else if (!FindNextFileNameW(h, &length, wname)) { | ||
1322 | FindClose(h); | ||
1323 | h = INVALID_HANDLE_VALUE; | ||
1324 | return 0; | ||
1325 | } | ||
1326 | WideCharToMultiByte(CP_ACP, 0, wname, -1, aname, PATH_MAX, NULL, NULL); | ||
1327 | realpath(aname, name); | ||
1328 | return 1; | ||
1329 | } | ||
1330 | #endif | ||