Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Respond to review comments. Use a larger buffer size, handle UNC path…
Browse files Browse the repository at this point in the history
…s, and check for errors.
  • Loading branch information
gruehle committed Nov 27, 2013
1 parent 28fed72 commit fd6fd6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion appshell/appshell_extensions_mac.mm
Expand Up @@ -543,11 +543,12 @@ int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double

// If path is a symlink, resolve it here and get the attributes at the
// resolved path
realPath = "";
if ([[fileAttribs fileType] isEqualToString:NSFileTypeSymbolicLink]) {
NSString* realPathStr = [path stringByResolvingSymlinksInPath];
realPath = [realPathStr UTF8String];
fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:realPathStr error:&error];
} else {
realPath = "";
}

NSDate *modDate = [fileAttribs valueForKey:NSFileModificationDate];
Expand Down
26 changes: 22 additions & 4 deletions appshell/appshell_extensions_win.cpp
Expand Up @@ -40,6 +40,10 @@
#define UNICODE_LEFT_ARROW 0x2190
#define UNICODE_DOWN_ARROW 0x2193

// Arbitrarily large size for path name buffers. Paths *could* contain
// up to 32768 characters, but this buffer should be large enough to handle
// any reasonable path.
#define PATH_BUFFER_SIZE 4096

// Forward declarations for functions at the bottom of this file
void ConvertToNativePath(ExtensionString& filename);
Expand Down Expand Up @@ -676,14 +680,28 @@ int32 GetFileInfo(ExtensionString filename, uint32& modtime, bool& isDir, double
if (dwAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
HANDLE hFile;

hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
wchar_t pathBuffer[MAX_PATH];
wchar_t pathBuffer[PATH_BUFFER_SIZE + 1];
DWORD nChars;

::GetFinalPathNameByHandleW(hFile, pathBuffer, MAX_PATH, 0);
nChars = ::GetFinalPathNameByHandleW(hFile, pathBuffer, PATH_BUFFER_SIZE, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
if (nChars && nChars <= PATH_BUFFER_SIZE) {
// Path returned by GetFilePathNameByHandle starts with "\\?\". Remove from returned value.
realPath = &pathBuffer[4];

// UNC paths start with UNC. Update here, if needed.
if (realPath.find(L"UNC") == 0) {
realPath = L"\\" + ExtensionString(&pathBuffer[7]);
}

ConvertToUnixPath(realPath);
}
::CloseHandle(hFile);
realPath = &pathBuffer[4]; // Path returned by GetFilePathNameByHandle starts with "\\?\". Remove from returned value.
}

// Note: all realPath errors are ignored. If the realPath can't be determined, it should not make the
// stat fail.
}

return NO_ERROR;
Expand Down

0 comments on commit fd6fd6f

Please sign in to comment.