Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: calling CreatefileW with CREATE_NEW flag for an exsiting file should fail #5682

Open
chenjie4255 opened this issue Feb 19, 2025 · 0 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@chenjie4255
Copy link
Contributor

What happened:

returned success with a file handle.

What you expected to happen:

should return INVALID_HANDLE_VALUE

How to reproduce it (as minimally and precisely as possible):

compile the following code

	const wchar_t* filename = argv[1];
	HANDLE hFile = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
	if (hFile == INVALID_HANDLE_VALUE) {
		auto lastError = GetLastError();
		std::wcerr << L"Failed to create file, error: " << lastError << std::endl;
		return lastError;
	}
	else {
		std::wcout << L"File created successfully" << std::endl;
	}

	CloseHandle(hFile);

	hFile = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
	if (hFile == INVALID_HANDLE_VALUE) {
		auto lastError = GetLastError();
		std::wcerr << L"[Expcted] Failed to create file, error: " << lastError << std::endl;
		return 0;
	}
	else {
		std::wcout << L"[ERROR! Unexpected]File created successfully" << std::endl;
	}

	CloseHandle(hFile);

Environment:

  • JuiceFS version (use juicefs --version) or Hadoop Java SDK version: juicefs main branch(2/18/2025)
  • OS (e.g cat /etc/os-release): windows 10
@chenjie4255 chenjie4255 added the kind/bug Something isn't working label Feb 19, 2025
@chenjie4255 chenjie4255 self-assigned this Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant