Skip to content

Allow to use CreateFile with FILE_SHARE_DELETE for O_RDONLY#4073

Closed
csware wants to merge 4 commits intolibgit2:masterfrom
csware:NoLockFIles
Closed

Allow to use CreateFile with FILE_SHARE_DELETE for O_RDONLY#4073
csware wants to merge 4 commits intolibgit2:masterfrom
csware:NoLockFIles

Conversation

@csware
Copy link
Contributor

@csware csware commented Jan 8, 2017

This prevents FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache, because the file is not locked any more.

Without this commit there could be errors while operating in explorer when a file is checked (e.g. using git_repository_hashfile) in background.

@ethomson
Copy link
Member

I'm sympathetic to wanting FILE_SHARE_DELETE, but I'm a bit concerned about the potential implications. Do we really want to do this always or is it something that people should opt into?

What files are you seeing problems here? Working directory files or files in the git repository or both?

Anyway. I'm very open to this, but I think that a branch that does CreateFile and a branch that does _wopen is a bummer. Let's move all opens to do a CreateFile that emulates _wopen (_wopen is, IIRC, just a wrapper around CreateFile) and change the flags as we see fit. Does that make sense?

@csware
Copy link
Contributor Author

csware commented Jan 11, 2017

I was experiencing the issue mainly with working tree files (when calling git_repository_hashfile) - at first I added the CreateFile handling there but thought "Why not do it for every read-only open case".

I focussed on the read-only part because I saw no issue with mixing _wopen and CreateFile as _wopen is just a wrapper.

I can prepare a new patch which replaces all _wopen calls with CreateFile.

@ethomson
Copy link
Member

I was experiencing the issue mainly with working tree files (when calling git_repository_hashfile) - at first I added the CreateFile handling there but thought "Why not do it for every read-only open case".

That was my guess - I think I would still like to see an option that you can set to enable it instead of making this the new default; it seems like it could be a very breaking change for people who expect the locking.

I focussed on the read-only part because I saw no issue with mixing _wopen and CreateFile as _wopen is just a wrapper.

I can prepare a new patch which replaces all _wopen calls with CreateFile.

I don't think there's a technical problem in intermixing them, I would just like to reduce the cyclomatic complexity.

Thanks for tackling this!

@csware
Copy link
Contributor Author

csware commented Jan 11, 2017

How would you tackle the "opt-in"?

@ethomson
Copy link
Member

I think that I would like to see git_libgit2_opts expanded to learn how to set this...

There's a couple of options here. This could be as direct as:

git_libgit2_opts(GIT_OPT_SET_WINDOWS_SHAREMODE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)

And then passing those given flags directly to CreateFile...

Is that satisfactory for TortoiseGit?

@csware
Copy link
Contributor Author

csware commented Jan 11, 2017

Is that satisfactory for TortoiseGit?

I see no issues so far.

}

handle = CreateFileW(buf, desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation_disposition, flags_and_attributes, 0);
handle = CreateFileW(buf, desired_access, git_posix_w32__windows_sharemode, NULL, creation_disposition, flags_and_attributes, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setting is now applied for all files. This is ok for me, but my initial attempt was to implement this only for files which are read only.

@csware csware changed the title Use CreateFile with FILE_SHARE_DELETE for O_RDONLY Allow to use CreateFile with FILE_SHARE_DELETE for O_RDONLY Jan 14, 2017
@csware
Copy link
Contributor Author

csware commented Jan 18, 2017

@ethomson Updated.

csware added 4 commits March 25, 2017 12:14
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more.

Signed-off-by: Sven Strickroth <email@cs-ware.de>
@ethomson
Copy link
Member

This was merged in #4192 - thanks again, and sorry for the delay in getting this integrated!

@ethomson ethomson closed this Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants