Skip to content

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

Open
@chenjie4255

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions