Skip to content

Commit

Permalink
More cleanup sparse (#1368)
Browse files Browse the repository at this point in the history
* Normalize paths that are saved in the sparse table

* Add comment for how the IsRecursive for a sparse folder is set

* Add verification for mockCommand3 in GVFSDatabaseTests

* Rename sparse test

* Add some validation to sparse folder test

* Rename method that validate folders to ValidateFoldersInSparseList

* Add to and update the sparse tests

* Add tests for various paths for the sparse verb and trim spaces
  • Loading branch information
Kevin Willford committed Aug 5, 2019
1 parent a6243ad commit 2f23e65
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 66 deletions.
18 changes: 11 additions & 7 deletions GVFS/GVFS.Common/Database/SparseTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;

namespace GVFS.Common.Database
{
Expand All @@ -15,6 +14,11 @@ public SparseTable(IGVFSConnectionPool connectionPool)
this.connectionPool = connectionPool;
}

public static string NormalizePath(string path)
{
return path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim().Trim(Path.DirectorySeparatorChar);
}

public static void CreateTable(IDbConnection connection)
{
using (IDbCommand command = connection.CreateCommand())
Expand All @@ -24,21 +28,21 @@ public static void CreateTable(IDbConnection connection)
}
}

public void Add(string directory)
public void Add(string directoryPath)
{
try
{
using (IDbConnection connection = this.connectionPool.GetConnection())
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT OR REPLACE INTO Sparse (path) VALUES (@path);";
command.AddParameter("@path", DbType.String, directory);
command.AddParameter("@path", DbType.String, NormalizePath(directoryPath));
command.ExecuteNonQuery();
}
}
catch (Exception ex)
{
throw new GVFSDatabaseException($"{nameof(SparseTable)}.{nameof(this.Add)}({directory}) Exception: {ex.ToString()}", ex);
throw new GVFSDatabaseException($"{nameof(SparseTable)}.{nameof(this.Add)}({directoryPath}) Exception: {ex.ToString()}", ex);
}
}

Expand Down Expand Up @@ -68,21 +72,21 @@ public HashSet<string> GetAll()
}
}

public void Remove(string directory)
public void Remove(string directoryPath)
{
try
{
using (IDbConnection connection = this.connectionPool.GetConnection())
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = "DELETE FROM Sparse WHERE path = @path;";
command.AddParameter("@path", DbType.String, directory);
command.AddParameter("@path", DbType.String, NormalizePath(directoryPath));
command.ExecuteNonQuery();
}
}
catch (Exception ex)
{
throw new GVFSDatabaseException($"{nameof(SparseTable)}.{nameof(this.Remove)}({directory}) Exception: {ex.ToString()}", ex);
throw new GVFSDatabaseException($"{nameof(SparseTable)}.{nameof(this.Remove)}({directoryPath}) Exception: {ex.ToString()}", ex);
}
}
}
Expand Down
Loading

0 comments on commit 2f23e65

Please sign in to comment.