VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/path/RTPathRmCmd.cpp@ 44279

Last change on this file since 44279 was 44279, checked in by vboxsync, 12 years ago

One important thing I forgot.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.2 KB
Line 
1/* $Id: RTPathRmCmd.cpp 44279 2013-01-13 20:58:30Z vboxsync $ */
2/** @file
3 * IPRT - TAR Command.
4 */
5
6/*
7 * Copyright (C) 2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/path.h>
32
33#include <iprt/buildconfig.h>
34#include <iprt/ctype.h>
35#include <iprt/file.h>
36#include <iprt/dir.h>
37#include <iprt/getopt.h>
38#include <iprt/initterm.h>
39#include <iprt/message.h>
40#include <iprt/stream.h>
41#include <iprt/string.h>
42#include <iprt/symlink.h>
43
44
45/*******************************************************************************
46* Defined Constants And Macros *
47*******************************************************************************/
48#define RTPATHRMCMD_OPT_INTERACTIVE 1000
49#define RTPATHRMCMD_OPT_ONE_FILE_SYSTEM 1001
50#define RTPATHRMCMD_OPT_PRESERVE_ROOT 1002
51#define RTPATHRMCMD_OPT_NO_PRESERVE_ROOT 1003
52#define RTPATHRMCMD_OPT_MACHINE_READABLE 1004
53
54/** The max directory entry size. */
55#define RTPATHRM_DIR_MAX_ENTRY_SIZE 4096
56
57
58/*******************************************************************************
59* Structures and Typedefs *
60*******************************************************************************/
61/** Interactive option. */
62typedef enum
63{
64 RTPATHRMCMDINTERACTIVE_NONE = 1,
65 RTPATHRMCMDINTERACTIVE_ALL,
66 RTPATHRMCMDINTERACTIVE_ONCE
67 /** @todo possible that we should by default prompt if removing read-only
68 * files or files owned by someone else. We currently don't. */
69} RTPATHRMCMDINTERACTIVE;
70
71/**
72 * IPRT rm option structure.
73 */
74typedef struct RTPATHRMCMDOPTS
75{
76 /** Whether to delete recursively. */
77 bool fRecursive;
78 /** Whether to delete directories as well as other kinds of files. */
79 bool fDirsAndOther;
80 /** Whether to remove files without prompting and ignoring non-existing
81 * files. */
82 bool fForce;
83 /** Machine readable output. */
84 bool fMachineReadable;
85 /** Don't try remove root ('/') if set, otherwise don't treat root specially. */
86 bool fPreserveRoot;
87 /** Whether to keep to one file system. */
88 bool fOneFileSystem;
89 /** Whether to safely delete files (overwrite 3x before unlinking). */
90 bool fSafeDelete;
91 /** Whether to be verbose about the operation. */
92 bool fVerbose;
93 /** The interactive setting. */
94 RTPATHRMCMDINTERACTIVE enmInteractive;
95} RTPATHRMCMDOPTS;
96/** Pointer to the IPRT rm options. */
97typedef RTPATHRMCMDOPTS *PRTPATHRMCMDOPTS;
98
99
100/*******************************************************************************
101* Global Variables *
102*******************************************************************************/
103/** A bunch of zeros. */
104static uint8_t const g_abZeros[16384] = { 0 };
105/** A bunch of 0xFF bytes. (lazy init) */
106static uint8_t g_ab0xFF[16384];
107
108
109static void rtPathRmVerbose(PRTPATHRMCMDOPTS pOpts, const char *pszPath)
110{
111 if (!pOpts->fMachineReadable)
112 RTPrintf("%s\n", pszPath);
113}
114
115
116static int rtPathRmError(PRTPATHRMCMDOPTS pOpts, const char *pszPath, int rc,
117 const char *pszFormat, ...)
118{
119 if (pOpts->fMachineReadable)
120 RTPrintf("fname=%s%crc=%d%c", pszPath, rc);
121 else
122 {
123 va_list va;
124 va_start(va, pszFormat);
125 RTMsgErrorV(pszFormat, va);
126 va_end(va);
127 }
128 return rc;
129}
130
131
132/**
133 * Worker that removes a symbolic link.
134 *
135 * @returns IPRT status code, errors go via rtPathRmError.
136 * @param pOpts The RM options.
137 * @param pszPath The path to the symbolic link.
138 */
139static int rtPathRmOneSymlink(PRTPATHRMCMDOPTS pOpts, const char *pszPath)
140{
141 if (pOpts->fVerbose)
142 rtPathRmVerbose(pOpts, pszPath);
143 int rc = RTSymlinkDelete(pszPath, 0);
144 if (RT_FAILURE(rc))
145 return rtPathRmError(pOpts, pszPath, rc, "Error removing symbolic link '%s': %Rrc\n", pszPath, rc);
146 return rc;
147}
148
149
150/**
151 * Worker that removes a file.
152 *
153 * Currently used to delete both regular and special files.
154 *
155 * @returns IPRT status code, errors go via rtPathRmError.
156 * @param pOpts The RM options.
157 * @param pszPath The path to the file.
158 * @param pObjInfo The FS object info for the file.
159 */
160static int rtPathRmOneFile(PRTPATHRMCMDOPTS pOpts, const char *pszPath, PRTFSOBJINFO pObjInfo)
161{
162 int rc;
163 if (pOpts->fVerbose)
164 rtPathRmVerbose(pOpts, pszPath);
165
166 /*
167 * Wipe the file if requested and possible.
168 */
169 if (pOpts->fSafeDelete && RTFS_IS_FILE(pObjInfo->Attr.fMode))
170 {
171 /* Lazy init of the 0xff buffer. */
172 if (g_ab0xFF[0] != 0xff || g_ab0xFF[sizeof(g_ab0xFF) - 1] != 0xff)
173 memset(g_ab0xFF, 0xff, sizeof(g_ab0xFF));
174
175 RTFILE hFile;
176 rc = RTFileOpen(&hFile, pszPath, RTFILE_O_WRITE);
177 if (RT_FAILURE(rc))
178 return rtPathRmError(pOpts, pszPath, rc, "Opening '%s' for overwriting: %Rrc\n", pszPath, rc);
179
180 for (unsigned iPass = 0; iPass < 3; iPass++)
181 {
182 uint8_t const *pabFiller = iPass == 1 ? g_abZeros : g_ab0xFF;
183 size_t const cbFiller = iPass == 1 ? sizeof(g_abZeros) : sizeof(g_ab0xFF);
184
185 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_BEGIN, NULL);
186 if (RT_FAILURE(rc))
187 {
188 rc = rtPathRmError(pOpts, pszPath, rc, "Error seeking to start of '%s': %Rrc\n", pszPath, rc);
189 break;
190 }
191 for (RTFOFF cbLeft = pObjInfo->cbObject; cbLeft > 0; cbLeft -= cbFiller)
192 {
193 size_t cbToWrite = cbFiller;
194 if (cbLeft < (RTFOFF)cbToWrite)
195 cbToWrite = (size_t)cbLeft;
196 rc = RTFileWrite(hFile, pabFiller, cbToWrite, NULL);
197 if (RT_FAILURE(rc))
198 {
199 rc = rtPathRmError(pOpts, pszPath, rc, "Error writing to '%s': %Rrc\n", pszPath, rc);
200 break;
201 }
202 }
203 }
204
205 int rc2 = RTFileClose(hFile);
206 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
207 return rtPathRmError(pOpts, pszPath, rc2, "Closing '%s' failed: %Rrc\n", pszPath, rc);
208 if (RT_FAILURE(rc))
209 return rc;
210 }
211
212 /*
213 * Remove the file.
214 */
215 rc = RTFileDelete(pszPath);
216 if (RT_FAILURE(rc))
217 return rtPathRmError(pOpts, pszPath, rc,
218 RTFS_IS_FILE(pObjInfo->Attr.fMode)
219 ? "Error removing regular file '%s': %Rrc\n"
220 : "Error removing special file '%s': %Rrc\n",
221 pszPath, rc);
222 return rc;
223}
224
225
226/**
227 * Deletes one directory (if it's empty).
228 *
229 * @returns IPRT status code, errors go via rtPathRmError.
230 * @param pOpts The RM options.
231 * @param pszPath The path to the directory.
232 */
233static int rtPathRmOneDir(PRTPATHRMCMDOPTS pOpts, const char *pszPath)
234{
235 if (pOpts->fVerbose)
236 rtPathRmVerbose(pOpts, pszPath);
237
238 int rc = RTDirRemove(pszPath);
239 if (RT_FAILURE(rc))
240 return rtPathRmError(pOpts, pszPath, rc, "Error removing directory '%s': %Rrc", pszPath, rc);
241 return rc;
242}
243
244
245/**
246 * Recursively delete a directory.
247 *
248 * @returns IPRT status code, errors go via rtPathRmError.
249 * @param pOpts The RM options.
250 * @param pszPath Pointer to a writable buffer holding the path to
251 * the directory.
252 * @param cchPath The length of the path (avoid strlen).
253 * @param pDirEntry Pointer to a directory entry buffer that is
254 * RTPATHRM_DIR_MAX_ENTRY_SIZE bytes big.
255 * @param pObjInfo Pointer the FS object info for the directory.
256 * This will be modified.
257 */
258static int rtPathRmRecursive(PRTPATHRMCMDOPTS pOpts, char *pszPath, size_t cchPath, PRTDIRENTRY pDirEntry, PRTFSOBJINFO pObjInfo)
259{
260 /*
261 * Make sure the path ends with a slash.
262 */
263 if (!cchPath || !RTPATH_IS_SLASH(pszPath[cchPath - 1]))
264 {
265 if (cchPath + 1 >= RTPATH_MAX)
266 return rtPathRmError(pOpts, pszPath, VERR_BUFFER_OVERFLOW, "Buffer overflow fixing up '%s'.\n", pszPath);
267 pszPath[cchPath++] = RTPATH_SLASH;
268 pszPath[cchPath] = '\0';
269 }
270
271 /*
272 * Traverse the directory.
273 */
274 PRTDIR hDir;
275 int rc = RTDirOpen(&hDir, pszPath);
276 if (RT_FAILURE(rc))
277 return rtPathRmError(pOpts, pszPath, rc, "Error opening directory '%s': %Rrc", pszPath, rc);
278 int rcRet = VINF_SUCCESS;
279 for (;;)
280 {
281 /*
282 * Read the next entry, constructing an full path for it.
283 */
284 size_t cbEntry = RTPATHRM_DIR_MAX_ENTRY_SIZE;
285 rc = RTDirRead(hDir, pDirEntry, &cbEntry);
286 if (rc == VERR_NO_MORE_FILES)
287 {
288 pszPath[cchPath] = '\0';
289 rc = RTDirClose(hDir);
290 if (RT_FAILURE(rc))
291 return rtPathRmError(pOpts, pszPath, rc, "Error closing directory '%s': %Rrc", pszPath, rc);
292
293 /* Delete the directory. */
294 int rc2 = rtPathRmOneDir(pOpts, pszPath);
295 if (RT_FAILURE(rc2) && RT_SUCCESS(rcRet))
296 return rc2;
297 return rcRet;
298 }
299 if (RT_FAILURE(rc))
300 {
301 rc = rtPathRmError(pOpts, pszPath, rc, "Error reading directory '%s': %Rrc", pszPath, rc);
302 break;
303 }
304
305 /* Skip '.' and '..'. */
306 if ( pDirEntry->szName[0] == '.'
307 && ( pDirEntry->cbName == 1
308 || ( pDirEntry->cbName == 2
309 && pDirEntry->szName[1] == '.')))
310 continue;
311
312 /* Construct full path. */
313 if (cchPath + pDirEntry->cbName > RTPATH_MAX)
314 {
315 pszPath[cchPath] = '\0';
316 rc = rtPathRmError(pOpts, pszPath, VERR_BUFFER_OVERFLOW, "Path buffer overflow in directory '%s'.", pszPath);
317 break;
318 }
319 memcpy(pszPath + cchPath, pDirEntry->szName, pDirEntry->cbName + 1);
320
321 /*
322 * Just query the full path info as we'll need it.
323 */
324 rc = RTPathQueryInfoEx(pszPath, pObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
325 if (RT_FAILURE(rc))
326 {
327 rc = rtPathRmError(pOpts, pszPath, rc, "RTPathQueryInfoEx failed on '%s': %Rrc", pszPath, rc);
328 if (RT_SUCCESS(rcRet))
329 rcRet = rc;
330 }
331
332 /*
333 * Take action according to the type.
334 */
335 switch (pObjInfo->Attr.fMode & RTFS_TYPE_MASK)
336 {
337 case RTFS_TYPE_FILE:
338 rc = rtPathRmOneFile(pOpts, pszPath, pObjInfo);
339 break;
340
341 case RTFS_TYPE_DIRECTORY:
342 rc = rtPathRmRecursive(pOpts, pszPath, cchPath, pDirEntry, pObjInfo);
343 break;
344
345 case RTFS_TYPE_SYMLINK:
346 rc = rtPathRmOneSymlink(pOpts, pszPath);
347 break;
348
349 case RTFS_TYPE_FIFO:
350 case RTFS_TYPE_DEV_CHAR:
351 case RTFS_TYPE_DEV_BLOCK:
352 case RTFS_TYPE_SOCKET:
353 rc = rtPathRmOneFile(pOpts, pszPath, pObjInfo);
354 break;
355
356 case RTFS_TYPE_WHITEOUT:
357 default:
358 rc = rtPathRmError(pOpts, pszPath, VERR_UNEXPECTED_FS_OBJ_TYPE,
359 "Object '%s' has an unknown file type: %o\n", pszPath, pObjInfo->Attr.fMode & RTFS_TYPE_MASK);
360 break;
361 }
362 if (RT_FAILURE(rc) && RT_SUCCESS(rcRet))
363 rcRet = rc;
364 }
365
366 RTDirClose(hDir);
367 return rc;
368}
369
370
371/**
372 * Remove one user specified file or directory.
373 *
374 * @returns IPRT status code, errors go via rtPathRmError.
375 * @param pOpts The RM options.
376 * @param pszPath The path to the file, directory, whatever.
377 */
378static int rtPathRmOne(PRTPATHRMCMDOPTS pOpts, const char *pszPath)
379{
380 /*
381 * Refuse to remove '.' and '..'.
382 */
383 const char *pszFilename = RTPathFilename(pszPath);
384 if ( pszFilename[0] == '.'
385 && ( pszFilename[1] == '\0'
386 || (pszFilename[1] == '.' && pszFilename[2] == '\0')))
387 return rtPathRmError(pOpts, pszPath, VERR_CANT_DELETE_DIRECTORY, "Cannot remove directory '%s'.\n", pszPath);
388
389 /*
390 * Query file system object info.
391 */
392 RTFSOBJINFO ObjInfo;
393 int rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK);
394 if (RT_FAILURE(rc))
395 {
396 if (pOpts->fForce && (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND))
397 return VINF_SUCCESS;
398 return rtPathRmError(pOpts, pszPath, rc, "Error deleting '%s': %Rrc", pszPath, rc);
399 }
400
401 /*
402 * Take type specific action.
403 */
404 switch (ObjInfo.Attr.fMode & RTFS_TYPE_MASK)
405 {
406 case RTFS_TYPE_FILE:
407 return rtPathRmOneFile(pOpts, pszPath, &ObjInfo);
408
409 case RTFS_TYPE_DIRECTORY:
410 if (pOpts->fRecursive)
411 {
412 char szPath[RTPATH_MAX];
413 rc = RTPathAbs(pszPath, szPath, sizeof(szPath));
414 if (RT_FAILURE(rc))
415 return rtPathRmError(pOpts, pszPath, rc, "RTPathAbs failed on '%s': %Rrc\n", pszPath, rc);
416
417 union
418 {
419 RTDIRENTRY Core;
420 uint8_t abPadding[RTPATHRM_DIR_MAX_ENTRY_SIZE];
421 } DirEntry;
422
423 return rtPathRmRecursive(pOpts, szPath, strlen(szPath), &DirEntry.Core, &ObjInfo);
424 }
425 if (pOpts->fDirsAndOther)
426 return rtPathRmOneDir(pOpts, pszPath);
427 return rtPathRmError(pOpts, pszPath, VERR_IS_A_DIRECTORY, "Cannot remove '%s': %Rrc\n", pszPath, VERR_IS_A_DIRECTORY);
428
429 case RTFS_TYPE_SYMLINK:
430 return rtPathRmOneSymlink(pOpts, pszPath);
431
432 case RTFS_TYPE_FIFO:
433 case RTFS_TYPE_DEV_CHAR:
434 case RTFS_TYPE_DEV_BLOCK:
435 case RTFS_TYPE_SOCKET:
436 return rtPathRmOneFile(pOpts, pszPath, &ObjInfo);
437
438 case RTFS_TYPE_WHITEOUT:
439 default:
440 return rtPathRmError(pOpts, pszPath, VERR_UNEXPECTED_FS_OBJ_TYPE,
441 "Object '%s' has an unknown file type: %o\n", pszPath, ObjInfo.Attr.fMode & RTFS_TYPE_MASK);
442
443 }
444}
445
446
447RTDECL(RTEXITCODE) RTPathRmCmd(unsigned cArgs, char **papszArgs)
448{
449 /*
450 * Parse the command line.
451 */
452 static const RTGETOPTDEF s_aOptions[] =
453 {
454 /* operations */
455 { "--dirs-and-more", 'd', RTGETOPT_REQ_NOTHING },
456 { "--force", 'f', RTGETOPT_REQ_NOTHING },
457 { "--prompt", 'i', RTGETOPT_REQ_NOTHING },
458 { "--prompt-once", 'I', RTGETOPT_REQ_NOTHING },
459 { "--interactive", RTPATHRMCMD_OPT_INTERACTIVE, RTGETOPT_REQ_STRING },
460 { "--one-file-system", RTPATHRMCMD_OPT_ONE_FILE_SYSTEM, RTGETOPT_REQ_NOTHING },
461 { "--preserve-root", RTPATHRMCMD_OPT_PRESERVE_ROOT, RTGETOPT_REQ_NOTHING },
462 { "--no-preserve-root", RTPATHRMCMD_OPT_NO_PRESERVE_ROOT, RTGETOPT_REQ_NOTHING },
463 { "--recursive", 'R', RTGETOPT_REQ_NOTHING },
464 { "--recursive", 'r', RTGETOPT_REQ_NOTHING },
465 { "--safe-delete", 'P', RTGETOPT_REQ_NOTHING },
466 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
467
468 /* IPRT extensions */
469 { "--machine-readable", RTPATHRMCMD_OPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING },
470 { "--machinereadable", RTPATHRMCMD_OPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING }, /* bad long option style */
471 };
472
473 RTGETOPTSTATE GetState;
474 int rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
475 RTGETOPTINIT_FLAGS_OPTS_FIRST);
476 if (RT_FAILURE(rc))
477 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOpt failed: %Rrc", rc);
478
479 RTPATHRMCMDOPTS Opts;
480 RT_ZERO(Opts);
481 Opts.fPreserveRoot = true;
482 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_NONE;
483
484 RTGETOPTUNION ValueUnion;
485 while ( (rc = RTGetOpt(&GetState, &ValueUnion)) != 0
486 && rc != VINF_GETOPT_NOT_OPTION)
487 {
488 switch (rc)
489 {
490 case 'd':
491 Opts.fDirsAndOther = true;
492 break;
493
494 case 'f':
495 Opts.fForce = true;
496 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_NONE;
497 break;
498
499 case 'i':
500 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_ALL;
501 break;
502
503 case 'I':
504 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_ONCE;
505 break;
506
507 case RTPATHRMCMD_OPT_INTERACTIVE:
508 if (!strcmp(ValueUnion.psz, "always"))
509 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_ALL;
510 else if (!strcmp(ValueUnion.psz, "once"))
511 Opts.enmInteractive = RTPATHRMCMDINTERACTIVE_ONCE;
512 else
513 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown --interactive option value: '%s'\n", ValueUnion.psz);
514 break;
515
516 case RTPATHRMCMD_OPT_ONE_FILE_SYSTEM:
517 Opts.fOneFileSystem = true;
518 break;
519
520 case RTPATHRMCMD_OPT_PRESERVE_ROOT:
521 Opts.fPreserveRoot = true;
522 break;
523
524 case RTPATHRMCMD_OPT_NO_PRESERVE_ROOT:
525 Opts.fPreserveRoot = false;
526 break;
527
528 case 'R':
529 case 'r':
530 Opts.fRecursive = true;
531 Opts.fDirsAndOther = true;
532 break;
533
534 case 'P':
535 Opts.fSafeDelete = true;
536 break;
537
538 case 'v':
539 Opts.fVerbose = true;
540 break;
541
542
543 case RTPATHRMCMD_OPT_MACHINE_READABLE:
544 Opts.fMachineReadable = true;
545 break;
546
547 case 'h':
548 RTPrintf("Usage: to be written\nOption dump:\n");
549 for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
550 if (RT_C_IS_PRINT(s_aOptions[i].iShort))
551 RTPrintf(" -%c,%s\n", s_aOptions[i].iShort, s_aOptions[i].pszLong);
552 else
553 RTPrintf(" %s\n", s_aOptions[i].pszLong);
554 return RTEXITCODE_SUCCESS;
555
556 case 'V':
557 RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
558 return RTEXITCODE_SUCCESS;
559
560 default:
561 return RTGetOptPrintError(rc, &ValueUnion);
562 }
563 }
564
565 /*
566 * Options we don't support.
567 */
568 if (Opts.fOneFileSystem)
569 return RTMsgErrorExit(RTEXITCODE_FAILURE, "The --one-file-system option is not yet implemented.\n");
570 if (Opts.enmInteractive != RTPATHRMCMDINTERACTIVE_NONE)
571 return RTMsgErrorExit(RTEXITCODE_FAILURE, "The -i, -I and --interactive options are not implemented yet.\n");
572
573 /*
574 * No files means error.
575 */
576 if (rc != VINF_GETOPT_NOT_OPTION && !Opts.fForce)
577 return RTMsgErrorExit(RTEXITCODE_FAILURE, "No files or directories specified.\n");
578
579 /*
580 * Machine readable init + header.
581 */
582 if (Opts.fMachineReadable)
583 {
584 rc = RTStrmSetMode(g_pStdOut, true /*fBinary*/, false /*fCurrentCodeSet*/);
585 if (RT_FAILURE(rc))
586 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTStrmSetMode failed: %Rrc.\n", rc);
587 static const char s_achHeader[] = "hdr_id=rm\0hdr_ver=1";
588 RTStrmWrite(g_pStdOut, s_achHeader, sizeof(s_achHeader));
589 }
590
591 /*
592 * Delete the specified files/dirs/whatever.
593 */
594 RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
595 while (rc == VINF_GETOPT_NOT_OPTION)
596 {
597 rc = rtPathRmOne(&Opts, ValueUnion.psz);
598 if (RT_FAILURE(rc))
599 rcExit = RTEXITCODE_FAILURE;
600
601 /* next */
602 rc = RTGetOpt(&GetState, &ValueUnion);
603 }
604 if (rc != 0)
605 rcExit = RTGetOptPrintError(rc, &ValueUnion);
606
607 /*
608 * Terminate the machine readable stuff.
609 */
610 if (Opts.fMachineReadable)
611 {
612 RTStrmWrite(g_pStdOut, "\0\0\0", 4);
613 rc = RTStrmFlush(g_pStdOut);
614 if (RT_FAILURE(rc) && rcExit == RTEXITCODE_SUCCESS)
615 rcExit = RTEXITCODE_FAILURE;
616 }
617
618 return rcExit;
619}
620
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette