| 900 | } |
| 901 | |
| 902 | bool removeAll(const FilePath& _filePath, Error* _err) |
| 903 | { |
| 904 | BX_ERROR_SCOPE(_err); |
| 905 | |
| 906 | if (remove(_filePath, _err) ) |
| 907 | { |
| 908 | return true; |
| 909 | } |
| 910 | |
| 911 | _err->reset(); |
| 912 | |
| 913 | FileInfo fi; |
| 914 | |
| 915 | if (!stat(fi, _filePath) ) |
| 916 | { |
| 917 | BX_ERROR_SET(_err, kErrorAccess, "The parent directory does not allow write permission to the process."); |
| 918 | return false; |
| 919 | } |
| 920 | |
| 921 | if (FileType::Dir != fi.type) |
| 922 | { |
| 923 | BX_ERROR_SET(_err, kErrorNotDirectory, "File already exist, and is not directory."); |
| 924 | return false; |
| 925 | } |
| 926 | |
| 927 | Error err; |
| 928 | DirectoryReader dr; |
| 929 | |
| 930 | if (!open(&dr, _filePath, &err) ) |
| 931 | { |
| 932 | BX_ERROR_SET(_err, kErrorNotDirectory, "File already exist, and is not directory."); |
| 933 | return false; |
| 934 | } |
| 935 | |
| 936 | while (err.isOk() ) |
| 937 | { |
| 938 | read(&dr, fi, &err); |
| 939 | |
| 940 | if (err.isOk() ) |
| 941 | { |
| 942 | if (0 == strCmp(fi.filePath, ".") |
| 943 | || 0 == strCmp(fi.filePath, "..") ) |
| 944 | { |
| 945 | continue; |
| 946 | } |
| 947 | |
| 948 | FilePath path(_filePath); |
| 949 | path.join(fi.filePath); |
| 950 | if (!removeAll(path, _err) ) |
| 951 | { |
| 952 | _err->reset(); |
| 953 | break; |
| 954 | } |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | close(&dr); |
| 959 | |