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

Mac: Don't download file sizes as part of OnEnumerateDirectory #1398

Merged
merged 2 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions GVFS/GVFS.Platform.Mac/MacFileSystemVirtualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class MacFileSystemVirtualizer : FileSystemVirtualizer
{
public static readonly byte[] PlaceholderVersionId = ToVersionIdByteArray(new byte[] { PlaceholderVersion });

private const int SymLinkTargetBufferSize = 4096;
private const int SymLinkTargetBufferSize = 4096;
private const long DummyFileSize = -1;

private const string ClassName = nameof(MacFileSystemVirtualizer);

Expand Down Expand Up @@ -83,6 +84,12 @@ public override void Stop()
this.Context.Tracer.RelatedEvent(EventLevel.Informational, $"{nameof(this.Stop)}_StopRequested", metadata: null);
}

/// <summary>
/// Writes a placeholder file.
/// </summary>
/// <param name="relativePath">Placeholder's path relative to the root of the repo</param>
/// <param name="endOfFile">Length of the file (ignored on this platform)</param>
/// <param name="sha">The SHA of the placeholder's contents, stored as the content ID in the placeholder</param>
public override FileSystemResult WritePlaceholderFile(
string relativePath,
long endOfFile,
Expand All @@ -99,7 +106,6 @@ public override FileSystemResult WritePlaceholderFile(
relativePath,
wilbaker marked this conversation as resolved.
Show resolved Hide resolved
PlaceholderVersionId,
ToVersionIdByteArray(FileSystemVirtualizer.ConvertShaToContentId(sha)),
(ulong)endOfFile,
fileMode);

return new FileSystemResult(ResultToFSResult(result), unchecked((int)result));
Expand Down Expand Up @@ -560,31 +566,12 @@ private Result OnEnumerateDirectory(
{
try
{
Result result;
try
{
IEnumerable<ProjectedFileInfo> projectedItems;

// TODO: Pool these connections or schedule this work to run asynchronously using TryScheduleFileOrNetworkRequest
using (BlobSizes.BlobSizesConnection blobSizesConnection = this.FileSystemCallbacks.BlobSizes.CreateConnection())
{
projectedItems = this.FileSystemCallbacks.GitIndexProjection.GetProjectedItems(CancellationToken.None, blobSizesConnection, relativePath);
}

result = this.CreatePlaceholders(relativePath, projectedItems, triggeringProcessName);
}
catch (SizesUnavailableException e)
{
// TODO: Is this the correct Result to return?
result = Result.EIOError;

EventMetadata metadata = this.CreateEventMetadata(relativePath, e);
metadata.Add("commandId", commandId);
metadata.Add(nameof(result), result.ToString("X") + "(" + result.ToString("G") + ")");
this.Context.Tracer.RelatedError(metadata, nameof(this.OnEnumerateDirectory) + ": caught SizesUnavailableException");
}
IEnumerable<ProjectedFileInfo> projectedItems = this.FileSystemCallbacks.GitIndexProjection.GetProjectedItems(
CancellationToken.None,
blobSizesConnection: null,
folderPath: relativePath);

return result;
return this.CreatePlaceholders(relativePath, projectedItems, triggeringProcessName);
}
catch (Exception e)
{
Expand Down Expand Up @@ -612,7 +599,9 @@ private Result CreatePlaceholders(string directoryRelativePath, IEnumerable<Proj
else
{
sha = fileInfo.Sha.ToString();
fileSystemResult = this.WritePlaceholderFile(childRelativePath, fileInfo.Size, sha);

// Writing placeholders on Mac does not require a file size
fileSystemResult = this.WritePlaceholderFile(childRelativePath, DummyFileSize, sha);
}

Result result = (Result)fileSystemResult.RawResult;
Expand Down
1 change: 0 additions & 1 deletion GVFS/GVFS.UnitTests/Mock/Mac/MockVirtualizationInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public override Result WritePlaceholderFile(
string relativePath,
byte[] providerId,
byte[] contentId,
ulong fileSize,
ushort fileMode)
{
this.CreatedPlaceholders.TryAdd(relativePath, fileMode);
Expand Down
23 changes: 17 additions & 6 deletions GVFS/GVFS.Virtualization/Projection/GitIndexProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ public virtual void GetFileTypeAndMode(string filePath, out FileType fileType, o
}
}

/// <summary>
/// Gets the projected items within the specified folder.
/// </summary>
/// <param name="cancellationToken">Cancellation token</param>
/// <param name="blobSizesConnection">
/// BlobSizes database connection, if null file sizes will not be populated
/// </param>
/// <param name="folderPath">Path of the folder relative to the repo's root</param>
public virtual List<ProjectedFileInfo> GetProjectedItems(
CancellationToken cancellationToken,
BlobSizes.BlobSizesConnection blobSizesConnection,
Expand All @@ -396,12 +404,15 @@ public virtual List<ProjectedFileInfo> GetProjectedItems(
FolderData folderData;
if (this.TryGetOrAddFolderDataFromCache(folderPath, out folderData))
{
folderData.PopulateSizes(
this.context.Tracer,
this.gitObjects,
blobSizesConnection,
availableSizes: null,
cancellationToken: cancellationToken);
if (blobSizesConnection != null)
{
folderData.PopulateSizes(
this.context.Tracer,
this.gitObjects,
blobSizesConnection,
availableSizes: null,
cancellationToken: cancellationToken);
}

return ConvertToProjectedFileInfos(folderData.ChildEntries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ private Result OnEnumerateDirectory(
Path.Combine(relativePath, child.Name),
providerId: ToVersionIdByteArray(1),
contentId: ToVersionIdByteArray(0),
fileSize: (ulong)child.Size,
fileMode: fileMode);
if (result != Result.Success)
{
Expand Down
1 change: 0 additions & 1 deletion ProjFS.Mac/PrjFSLib.Mac.Managed/Interop/PrjFSLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static extern Result WritePlaceholderFile(
byte[] providerId,
[MarshalAs(UnmanagedType.LPArray, SizeConst = PlaceholderIdLength)]
byte[] contentId,
ulong fileSize,
ushort fileMode);

[DllImport(PrjFSLibPath, EntryPoint = "PrjFS_WriteSymLink")]
Expand Down
2 changes: 0 additions & 2 deletions ProjFS.Mac/PrjFSLib.Mac.Managed/VirtualizationInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public virtual Result WritePlaceholderFile(
string relativePath,
byte[] providerId,
byte[] contentId,
ulong fileSize,
ushort fileMode)
{
if (providerId.Length != Interop.PrjFSLib.PlaceholderIdLength ||
Expand All @@ -107,7 +106,6 @@ public virtual Result WritePlaceholderFile(
relativePath,
providerId,
contentId,
fileSize,
fileMode);
}

Expand Down
4 changes: 1 addition & 3 deletions ProjFS.Mac/PrjFSLib/PrjFSLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ PrjFS_Result PrjFS_WritePlaceholderFile(
_In_ const char* relativePath,
_In_ unsigned char providerId[PrjFS_PlaceholderIdLength],
_In_ unsigned char contentId[PrjFS_PlaceholderIdLength],
_In_ unsigned long fileSize,
_In_ uint16_t fileMode)
{
#ifdef DEBUG
Expand All @@ -357,7 +356,6 @@ PrjFS_Result PrjFS_WritePlaceholderFile(
<< relativePath << ", "
<< (int)providerId[0] << ", "
<< (int)contentId[0] << ", "
<< fileSize << ", "
<< oct << fileMode << dec << ")" << endl;
#endif

Expand Down Expand Up @@ -494,7 +492,7 @@ PrjFS_Result PrjFS_UpdatePlaceholderFileIfNeeded(
}

// TODO(#1372): Ensure that races with hydration are handled properly
return PrjFS_WritePlaceholderFile(relativePath, providerId, contentId, fileSize, fileMode);
return PrjFS_WritePlaceholderFile(relativePath, providerId, contentId, fileMode);
}

PrjFS_Result PrjFS_ReplacePlaceholderFileWithSymLink(
Expand Down
1 change: 0 additions & 1 deletion ProjFS.Mac/PrjFSLib/PrjFSLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ extern "C" PrjFS_Result PrjFS_WritePlaceholderFile(
_In_ const char* relativePath,
_In_ unsigned char providerId[PrjFS_PlaceholderIdLength],
_In_ unsigned char contentId[PrjFS_PlaceholderIdLength],
_In_ unsigned long fileSize,
_In_ uint16_t fileMode);

extern "C" PrjFS_Result PrjFS_WriteSymLink(
Expand Down