Fixed filters to include everything if empty.

Will now include by default if there are only exclude filters.
If there are any include filters, the files are excluded by default.
This commit is contained in:
Kenneth Skovhede
2013-06-30 12:42:13 +02:00
parent fd3259b998
commit b69cdcb136
11 changed files with 42 additions and 24 deletions
@@ -755,7 +755,7 @@ namespace Duplicati.Library.Main.Database
while(rd.Read())
{
var p = rd.GetValue(0).ToString();
if(Library.Utility.FilterExpression.Matches(filter, p, true))
if(Library.Utility.FilterExpression.Matches(filter, p))
{
cmd.SetParameterValue(0, p);
cmd.ExecuteNonQuery();
@@ -175,7 +175,7 @@ namespace Duplicati.Library.Main.Database
while (rd.Read())
{
rd.GetValues(values);
if (values[0] != null && values[0] != DBNull.Value && Library.Utility.FilterExpression.Matches(filter, values[0].ToString(), true))
if (values[0] != null && values[0] != DBNull.Value && Library.Utility.FilterExpression.Matches(filter, values[0].ToString()))
{
cmd2.SetParameterValue(0, values[0]);
cmd2.SetParameterValue(1, values[1]);
@@ -117,7 +117,7 @@ namespace Duplicati.Library.Main.Database
while (rd.Read())
{
rd.GetValues(values);
if (values[0] != null && values[0] != DBNull.Value && Library.Utility.FilterExpression.Matches(filter, values[0].ToString(), true))
if (values[0] != null && values[0] != DBNull.Value && Library.Utility.FilterExpression.Matches(filter, values[0].ToString()))
{
cmd2.SetParameterValue(0, values[0]);
cmd2.SetParameterValue(1, values[1]);
@@ -156,7 +156,7 @@ namespace Duplicati.Library.Main.Operation
return false;
}
if (!Library.Utility.FilterExpression.Matches(m_filter, path, true))
if (!Library.Utility.FilterExpression.Matches(m_filter, path))
{
m_result.AddVerboseMessage("Excluding path due to filter {0}", path);
return false;
@@ -130,13 +130,13 @@ namespace Duplicati.Library.Main.Operation
using(var tmpfile = backend.Get(baseFile.File.Name, baseFile.File.Size, null))
using(var rd = new Volumes.FilesetVolumeReader(RestoreHandler.GetCompressionModule(baseFile.File.Name), tmpfile, m_options))
foreach(var f in rd.Files)
if (Library.Utility.FilterExpression.Matches(filter, f.Path, true))
if (Library.Utility.FilterExpression.Matches(filter, f.Path))
storageKeeper.AddElement(f.Path, f.Hash, f.Metahash, f.Size, conv(f.Type), false);
using(var tmpfile = backend.Get(compareFile.File.Name, compareFile.File.Size, null))
using(var rd = new Volumes.FilesetVolumeReader(RestoreHandler.GetCompressionModule(compareFile.File.Name), tmpfile, m_options))
foreach(var f in rd.Files)
if (Library.Utility.FilterExpression.Matches(filter, f.Path, true))
if (Library.Utility.FilterExpression.Matches(filter, f.Path))
storageKeeper.AddElement(f.Path, f.Hash, f.Metahash, f.Size, conv(f.Type), true);
}
@@ -67,7 +67,7 @@ namespace Duplicati.Library.Main.Operation
using (var tmpfile = backend.Get(file.Name, size, hash))
using (var tmp = new Volumes.FilesetVolumeReader(RestoreHandler.GetCompressionModule(file.Name), tmpfile, m_options))
foreach (var cf in tmp.ControlFiles)
if (Library.Utility.FilterExpression.Matches(filter, cf.Key, true))
if (Library.Utility.FilterExpression.Matches(filter, cf.Key))
files.Add(new ListResultFile(cf.Key, null));
m_result.SetResult(new Library.Interface.IListResultFileset[] { new ListResultFileset(fileversion.Key, fileversion.Value.Time, -1, -1) }, files);
@@ -77,7 +77,7 @@ namespace Duplicati.Library.Main.Operation
m_result.SetResult(
numberSeq.Take(1),
(from n in rd.Files
where Library.Utility.FilterExpression.Matches(filter, n.Path, true)
where Library.Utility.FilterExpression.Matches(filter, n.Path)
orderby n.Path
select new ListResultFile(n.Path, new long[] { n.Size }))
.ToArray()
@@ -88,7 +88,7 @@ namespace Duplicati.Library.Main.Operation
else
{
res = rd.Files
.Where(x => Library.Utility.FilterExpression.Matches(filter, x.Path, true))
.Where(x => Library.Utility.FilterExpression.Matches(filter, x.Path))
.ToDictionary(
x => x.Path,
y =>
@@ -106,7 +106,7 @@ namespace Duplicati.Library.Main.Operation
using(var tmpfile = backend.Get(flentry.Value.File.Name, -1, null))
using (var rd = new Volumes.FilesetVolumeReader(flentry.Value.CompressionModule, tmpfile, m_options))
{
foreach(var p in from n in rd.Files where Library.Utility.FilterExpression.Matches(filter, n.Path, true) select n)
foreach(var p in from n in rd.Files where Library.Utility.FilterExpression.Matches(filter, n.Path) select n)
{
List<long> lst;
if (!res.TryGetValue(p.Path, out lst))
@@ -170,7 +170,7 @@ namespace Duplicati.Library.Main.Operation
// Create timestamped operations based on the file timestamp
backupdb.CreateFileset(volumeIds[entry.Name], parsed.Time, tr);
using (var filelistreader = new FilesetVolumeReader(parsed.CompressionModule, tmpfile, m_options))
foreach (var fe in filelistreader.Files.Where(x => Library.Utility.FilterExpression.Matches(filter, x.Path, true)))
foreach (var fe in filelistreader.Files.Where(x => Library.Utility.FilterExpression.Matches(filter, x.Path)))
{
if (fe.Type == FilelistEntryType.Folder)
{
@@ -56,7 +56,7 @@ namespace Duplicati.Library.Main.Operation
using (var tmpfile = backend.Get(file.Name, size, hash))
using (var tmp = new Volumes.FilesetVolumeReader(RestoreHandler.GetCompressionModule(file.Name), tmpfile, m_options))
foreach (var cf in tmp.ControlFiles)
if (Library.Utility.FilterExpression.Matches(filter, cf.Key, true))
if (Library.Utility.FilterExpression.Matches(filter, cf.Key))
{
var targetpath = System.IO.Path.Combine(m_options.Restorepath, cf.Key);
using (var ts = System.IO.File.Create(targetpath))
+24 -6
View File
@@ -200,17 +200,35 @@ namespace Duplicati.Library.Utility
/// </summary>
/// <param name="filter">The filter to evaluate</param>
/// <param name="path">The path to evaluate</param>
/// <param name="default">The default return value if no filter matches</param>
public static bool Matches(IFilter filter, string path, bool @default)
public static bool Matches(IFilter filter, string path)
{
if (filter == null || filter.Empty)
return @default;
return true;
bool result;
if (!filter.Matches(path, out result))
result = @default;
if (filter.Matches(path, out result))
return result;
// If we only exclude files, choose to include by default
var q = new Queue<IFilter>();
q.Enqueue(filter);
return result;
while (q.Count > 0)
{
var p = q.Dequeue();
if (p == null || p.Empty)
continue;
else if (p is FilterExpression && ((FilterExpression)filter).Result)
return false; // We have an include filter, so we exclude by default
else if (p is JoinedFilterExpression)
{
q.Enqueue(((JoinedFilterExpression)p).First);
q.Enqueue(((JoinedFilterExpression)p).Second);
}
}
// Only excludes, we return true
return true;
}
/// <summary>
@@ -21,21 +21,21 @@ namespace Duplicati.Library.Utility
{
public class JoinedFilterExpression : IFilter
{
private IFilter m_first;
private IFilter m_second;
public readonly IFilter First;
public readonly IFilter Second;
public JoinedFilterExpression(IFilter first, IFilter second)
{
m_first = first ?? new FilterExpression();
m_second = second ?? new FilterExpression();
this.First = first ?? new FilterExpression();
this.Second = second ?? new FilterExpression();
}
public bool Matches(string entry, out bool result)
{
return m_first.Matches(entry, out result) || m_second.Matches(entry, out result);
return First.Matches(entry, out result) || Second.Matches(entry, out result);
}
public bool Empty { get { return m_first.Empty && m_second.Empty; } }
public bool Empty { get { return First.Empty && Second.Empty; } }
public static IFilter Join(IFilter first, IFilter second)
{