MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / write_encrypted_long_name

Function write_encrypted_long_name

libcppcryptfs/filename/cryptfilename.cpp:855–894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

853
854#ifdef _WIN32
855bool write_encrypted_long_name(const WCHAR *filePath, const string& enc_data)
856{
857 if (enc_data.size() < 1)
858 return false;
859
860 if (!PathFileExists(filePath))
861 return true;
862
863 wstring path = filePath;
864
865 if (path[path.size() - 1] == '\\')
866 path.erase(path.size() - 1);
867
868 path += longname_suffix;
869
870 if (PathFileExists(&path[0]))
871 return true;
872
873 HANDLE hFile = CreateFile(&path[0], GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
874
875 if (hFile == INVALID_HANDLE_VALUE)
876 return false;
877
878 if (GetLastError() == ERROR_ALREADY_EXISTS) {
879 CloseHandle(hFile);
880 return true;
881 }
882
883 DWORD nWritten = 0;
884
885 if (!WriteFile(hFile, &enc_data[0], (DWORD)enc_data.size(), &nWritten, NULL)) {
886 CloseHandle(hFile);
887 return false;
888 }
889
890 CloseHandle(hFile);
891
892 return nWritten == enc_data.size();
893
894}
895
896#endif // _WIN32
897

Callers 2

CryptMoveFileInternalFunction · 0.85

Calls 2

sizeMethod · 0.80
eraseMethod · 0.80

Tested by

no test coverage detected