Changeset 9f8691c956e3…
Parent b32528945028…
by
Changes to 4 files · Browse files at 9f8691c956e3 Showing diff from parent b32528945028 Diff from another changeset...
@@ -18,6 +18,7 @@
#include "DirectoryStatus.h"
#include "Thgstatus.h"
+#include "TortoiseUtils.h"
char DirectoryStatus::status(const std::string& relpath_) const
@@ -61,7 +62,7 @@
std::string p = hgroot + "\\.hg\\thgstatus";
- FILE *f = fopen(p.c_str(), "rb");
+ FILE *f = fopenReadRenameAllowed(p.c_str());
if (!f)
{
TDEBUG_TRACE("DirectoryStatus::read: can't open '" << p << "'");
|
@@ -4,6 +4,10 @@ #include "errno.h"
#include <assert.h>
+#include <io.h>
+#include "FCNTL.H"
+
+
int WideCharToLocal(LPTSTR pLocal, LPWSTR pWide, DWORD dwChars)
{
*pLocal = 0;
@@ -242,3 +246,36 @@ return !GetHgRepoRoot(path).empty();
}
+
+// open a file for reading, allowing renames and deletes by other
+// processes while we have it open
+FILE* fopenReadRenameAllowed(const char* path)
+{
+ HANDLE fh = ::CreateFileA(
+ path, GENERIC_READ,
+ FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
+ 0, OPEN_EXISTING, 0, 0
+ );
+
+ if (fh == INVALID_HANDLE_VALUE)
+ return 0;
+
+ // get C runtime file descriptor from file handle
+ int fd = ::_open_osfhandle((intptr_t)fh, _O_RDONLY);
+ if (fd == -1)
+ {
+ TDEBUG_TRACE("fopenReadRenameAllowed: _open_osfhandle failed");
+ return 0;
+ }
+
+ // get C runtime FILE from file descriptor
+ FILE* f = ::_fdopen(fd, "r");
+ if (f == 0)
+ {
+ TDEBUG_TRACE("fopenReadRenameAllowed: _fdopen failed");
+ return 0;
+ }
+
+ return f;
+}
+
|
@@ -38,5 +38,6 @@ std::string GetHgRepoRoot(const std::string& path);
bool IsHgRepo(const std::string& path);
int GetRegistryConfig(const std::string& name, std::string& res);
+FILE* fopenReadRenameAllowed(const char* path);
#endif
|
@@ -18,13 +18,14 @@ #include "stdafx.h"
#include "dirstate.h"
+#include "TortoiseUtils.h"
std::auto_ptr<Dirstate> Dirstate::read(const std::string& path, bool& unset)
{
unset = false;
- FILE *f = fopen(path.c_str(), "rb");
+ FILE *f = fopenReadRenameAllowed(path.c_str());
if (!f)
{
TDEBUG_TRACE("Dirstate::read: can't open " << path);
|
Loading...