#endregion
using System.Diagnostics.Contracts;
using System.IO;
+using System.Reflection;
using System.Threading.Tasks;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
+using Castle.ActiveRecord.Queries;
+using NHibernate.Criterion;
using Pithos.Core.Agents;
using Pithos.Interfaces;
using Pithos.Network;
namespace Pithos.Core
{
using System;
- using System.Collections.Generic;
- using System.Linq;
+ using System.Collections.Generic;
/// <summary>
/// TODO: Update summary.
[ActiveRecord]
public class FileState : ActiveRecordLinqBase<FileState>
{
- private static readonly ILog Log = LogManager.GetLogger("FileState");
+ private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
private IList<FileTag> _tags = new List<FileTag>();
throw;
}
}
+
+ /// <summary>
+ /// Mark Unversioned all FileState rows from the database whose path
+ /// starts with one of the removed paths
+ /// </summary>
+ /// <param name="removed"></param>
+ public static void UnversionPaths(List<string> removed)
+ {
+ if (removed == null)
+ return;
+ if (removed.Count == 0)
+ return;
+
+ //Create a disjunction (list of OR statements
+ var disjunction = new Disjunction();
+ foreach (var path in removed)
+ {
+ //with the restriction FileState.FilePath like '@path%'
+ disjunction.Add(Restrictions.On<FileState>(s => s.FilePath)
+ .IsLike(path, MatchMode.Start));
+ }
+
+ //Generate a query from the disjunction
+ var query=QueryOver.Of<FileState>().Where(disjunction);
+
+ ExecuteWithRetry((session,instance)=>
+ {
+ using (var t=session.BeginTransaction())
+ {
+ var states = query.GetExecutableQueryOver(session).List();
+ foreach (var state in states)
+ {
+ state.FileStatus = FileStatus.Unversioned;
+ state.OverlayStatus = FileOverlayStatus.Unversioned;
+ state.Update();
+ }
+ t.Commit();
+ }
+ return null;
+ },null);
+ }
+
}
[ActiveRecord("Tags")]