| 793 | } |
| 794 | |
| 795 | bool |
| 796 | delete_directory(CryptContext *con, LPCWSTR path) |
| 797 | { |
| 798 | bool bret = true; |
| 799 | |
| 800 | try { |
| 801 | |
| 802 | wstring path_with_slash = path; |
| 803 | |
| 804 | if (path_with_slash[path_with_slash.size() - 1] != '\\') |
| 805 | path_with_slash.push_back('\\'); |
| 806 | |
| 807 | vector<wstring> dummy; |
| 808 | |
| 809 | auto& files_to_delete = con ? con->GetDeletableFiles() : dummy; |
| 810 | |
| 811 | wstring file_to_delete; |
| 812 | |
| 813 | for (size_t i = 0; i < files_to_delete.size(); i++) { |
| 814 | |
| 815 | file_to_delete = path_with_slash + files_to_delete[i]; |
| 816 | |
| 817 | DWORD attr = GetFileAttributes(file_to_delete.c_str()); |
| 818 | |
| 819 | if (attr != INVALID_FILE_ATTRIBUTES) { |
| 820 | |
| 821 | if (attr & FILE_ATTRIBUTE_READONLY) { |
| 822 | attr &= ~FILE_ATTRIBUTE_READONLY; |
| 823 | if (!SetFileAttributes(file_to_delete.c_str(), attr)) { |
| 824 | throw((int)GetLastError()); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | if (!DeleteFile(file_to_delete.c_str())) { |
| 829 | throw((int)GetLastError()); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | if (con->GetConfig()->DirIV()) { |
| 835 | con->m_dir_iv_cache.remove(path); |
| 836 | } |
| 837 | |
| 838 | if (!RemoveDirectory(path)) { |
| 839 | throw((int)GetLastError()); |
| 840 | } |
| 841 | |
| 842 | if (!con->GetConfig()->m_PlaintextNames && con->GetConfig()->m_LongNames && is_long_name(path)) { |
| 843 | wstring name_file = path; |
| 844 | if (name_file[name_file.size()-1] == '\\') { |
| 845 | name_file.erase(name_file.size() - 1); |
| 846 | } |
| 847 | name_file += LONGNAME_SUFFIX_W; |
| 848 | |
| 849 | if (PathFileExists(&name_file[0])) { |
| 850 | if (!DeleteFile(&name_file[0])) { |
| 851 | throw((int)GetLastError()); |
| 852 | } |
no test coverage detected