private IEventAggregator _events ;
private string _rootPath;
- private string _fragmentsPath;
+ private string _cachePath;
public string RootPath
{
get { return _rootPath; }
set
{
_rootPath = value;
- _fragmentsPath = Path.Combine(_rootPath, FolderConstants.FragmentsFolder);
+ _cachePath = Path.Combine(_rootPath, FolderConstants.CacheFolder);
_pithosDirectory = new ObservableCollection<DirectoryRecord>{
- new DirectoryRecord(_fragmentsPath) {Info = new DirectoryInfo(value)}};
+ new DirectoryRecord(_cachePath) {Info = new DirectoryInfo(value)}};
NotifyOfPropertyChange(() => RootPath);
NotifyOfPropertyChange(()=>PithosDirectory);
}
[Test]
public void TestDownload()
{
- var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
+ var fileAgent = new FileAgent {CachePath = @"e:\pithos\.pithos.cache"};
var agent = new NetworkAgent();
public string FilePath { get; private set; }
public string RelativePath { get; private set; }
- public string FragmentsPath { get; private set; }
+ public string CachePath { get; private set; }
public TreeHash ServerHash { get; private set; }
[ContractInvariantMethod]
private void Invariants()
{
- Contract.Invariant(Path.IsPathRooted(FragmentsPath));
+ Contract.Invariant(Path.IsPathRooted(CachePath));
Contract.Invariant(Path.IsPathRooted(FilePath));
Contract.Invariant(Path.IsPathRooted(TempPath));
Contract.Invariant(!Path.IsPathRooted(RelativePath));
Contract.Invariant(ServerHash!=null);
}
- public BlockUpdater(string fragmentsPath, string filePath, string relativePath,TreeHash serverHash)
+ public BlockUpdater(string cachePath, string filePath, string relativePath,TreeHash serverHash)
{
- if (String.IsNullOrWhiteSpace(fragmentsPath))
- throw new ArgumentNullException("fragmentsPath");
- if (!Path.IsPathRooted(fragmentsPath))
- throw new ArgumentException("The fragmentsPath must be rooted", "fragmentsPath");
+ if (String.IsNullOrWhiteSpace(cachePath))
+ throw new ArgumentNullException("cachePath");
+ if (!Path.IsPathRooted(cachePath))
+ throw new ArgumentException("The cachePath must be rooted", "cachePath");
if (string.IsNullOrWhiteSpace(filePath))
throw new ArgumentNullException("filePath");
throw new ArgumentNullException("serverHash");
Contract.EndContractBlock();
- FragmentsPath=fragmentsPath;
+ CachePath=cachePath;
FilePath = filePath;
RelativePath=relativePath;
ServerHash = serverHash;
//The file will be stored in a temporary location while downloading with an extension .download
- TempPath = Path.Combine(FragmentsPath, RelativePath + ".download");
+ TempPath = Path.Combine(CachePath, RelativePath + ".download");
//Need to calculate the directory path because RelativePath may include folders
var directoryPath = Path.GetDirectoryName(TempPath);
//directoryPath CAN be null if TempPath is a root path
if (String.IsNullOrWhiteSpace(directoryPath))
throw new ArgumentException("TempPath");
- //FragmentsPath was absolute so directoryPath is absolute too
+ //CachePath was absolute so directoryPath is absolute too
Contract.Assume(Path.IsPathRooted(directoryPath));
if (!Directory.Exists(directoryPath))
}
}
- public string FragmentsPath { get; set; }
+ public string CachePath { get; set; }
private List<string> _selectivePaths = new List<string>();
public List<string> SelectivePaths
private bool Ignore(string filePath)
{
- if (filePath.StartsWith(FragmentsPath))
+ if (filePath.StartsWith(CachePath))
return true;
if (_ignoreFiles.ContainsKey(filePath.ToLower()))
return true;
//Post a Change message for all events except rename
void OnFileEvent(object sender, FileSystemEventArgs e)
{
- //Ignore events that affect the Fragments folder
+ //Ignore events that affect the cache folder
var filePath = e.FullPath;
if (Ignore(filePath))
return;
var remote = from info in remoteObjects.Union(sharedObjects)
let name = info.Name
where !name.EndsWith(".ignore", StringComparison.InvariantCultureIgnoreCase) &&
- !name.StartsWith("fragments/", StringComparison.InvariantCultureIgnoreCase)
+ !name.StartsWith(FolderConstants.CacheFolder +"/", StringComparison.InvariantCultureIgnoreCase)
select info;
//Create a list of actions from the remote files
if (gate.Failed)
yield break;
//The file's hashmap will be stored in the same location with the extension .hashmap
- //var hashPath = Path.Combine(FileAgent.FragmentsPath, relativePath + ".hashmap");
+ //var hashPath = Path.Combine(FileAgent.CachePath, relativePath + ".hashmap");
var client = new CloudFilesClient(accountInfo);
var account = cloudFile.Account;
//Calculate the relative file path for the new file
var relativePath = relativeUrl.RelativeUriToFilePath();
//The file will be stored in a temporary location while downloading with an extension .download
- var tempPath = Path.Combine(fileAgent.FragmentsPath, relativePath + ".download");
+ var tempPath = Path.Combine(fileAgent.CachePath, relativePath + ".download");
//Make sure the target folder exists. DownloadFileTask will not create the folder
var tempFolder = Path.GetDirectoryName(tempPath);
if (!Directory.Exists(tempFolder))
//Calculate the relative file path for the new file
var relativePath = relativeUrl.RelativeUriToFilePath();
- var blockUpdater = new BlockUpdater(fileAgent.FragmentsPath, localPath, relativePath, serverHash);
+ var blockUpdater = new BlockUpdater(fileAgent.CachePath, localPath, relativePath, serverHash);
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;
using Pithos.Interfaces;
+using Pithos.Network;
using log4net;
using log4net.Appender;
using log4net.Config;
private void CleanupStaleStates()
{
/*var stales = from state in FileState.Queryable
- where state.FilePath.StartsWith(@"e:\pithos\fragments")
+ where state.FilePath.StartsWith(@"e:\pithos\cache")
select state.Id;*/
- FileState.DeleteAll(@"FilePath like 'e:\pithos\fragments%'");
+ FileState.DeleteAll(@"FilePath like 'e:\pithos\.pithos.cache%'");
;
}
throw new ArgumentNullException("setter");
Contract.EndContractBlock();
- Debug.Assert(!path.Contains("fragments"));
+ Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
Debug.Assert(!path.EndsWith(".ignore"));
if (String.IsNullOrWhiteSpace(path))
[Import]
public IStatusKeeper StatusKeeper { get; set; }
- //We should avoid processing files stored in the Fragments folder
- //The Full path to the fragments folder is stored in FragmentsPath
- //public string FragmentsPath { get; set; }
-
[Import]
public NetworkAgent NetworkAgent { get; set; }
if (Log.IsDebugEnabled)
Log.Debug("Starting interrupted files");
- var fragmentsPath = Path.Combine(accountInfo.AccountPath, FolderConstants.FragmentsFolder)
+ var cachePath = Path.Combine(accountInfo.AccountPath, FolderConstants.CacheFolder)
.ToLower();
var pendingEntries = from state in FileState.Queryable
where state.FileStatus != FileStatus.Unchanged &&
- !state.FilePath.StartsWith(fragmentsPath) &&
+ !state.FilePath.StartsWith(cachePath) &&
!state.FilePath.EndsWith(".ignore") &&
state.FilePath.StartsWith(accountInfo.AccountPath)
select state;
_accountInfo = CloudClient.Authenticate();
_accountInfo.AccountPath = RootPath;
+ //Create the cache folder and ensure it is hidden
+ CreateHiddenFolder(RootPath, FolderConstants.CacheFolder);
+
var policy=CloudClient.GetAccountPolicies(_accountInfo);
StatusNotification.NotifyAccount(policy);
Log.Info("START");
try
{
- var fragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+ var cachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
var directory = new DirectoryInfo(RootPath);
var files =
from file in directory.EnumerateFiles("*", SearchOption.AllDirectories)
- where !file.FullName.StartsWith(fragmentsPath, StringComparison.InvariantCultureIgnoreCase) &&
+ where !file.FullName.StartsWith(cachePath, StringComparison.InvariantCultureIgnoreCase) &&
!file.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase)
select file;
StatusKeeper.ProcessExistingFiles(files);
NetworkAgent.ProcessRemoteFiles();
}
- //Make sure a hidden fragments folder exists to store partial downloads
+ //Make sure a hidden cache folder exists to store partial downloads
private static string CreateHiddenFolder(string rootPath, string folderName)
{
if (String.IsNullOrWhiteSpace(rootPath))
var info = Directory.CreateDirectory(folder);
info.Attributes |= FileAttributes.Hidden;
- Log.InfoFormat("Created Fragments Folder: {0}", folder);
+ Log.InfoFormat("Created cache Folder: {0}", folder);
+ }
+ else
+ {
+ var info = new DirectoryInfo(folder);
+ if ((info.Attributes & FileAttributes.Hidden) == 0)
+ {
+ info.Attributes |= FileAttributes.Hidden;
+ Log.InfoFormat("Reset cache folder to hidden: {0}", folder);
+ }
}
return folder;
}
FileAgent.StatusKeeper = StatusKeeper;
FileAgent.Workflow = Workflow;
- FileAgent.FragmentsPath = Path.Combine(RootPath, FolderConstants.FragmentsFolder);
+ FileAgent.CachePath = Path.Combine(RootPath, FolderConstants.CacheFolder);
FileAgent.Start(_accountInfo, RootPath);
}
using Pithos.Interfaces;
using System.IO;
using System.Diagnostics;
+using Pithos.Network;
namespace Pithos.Core
{
public FileStatus SetFileStatus(string path, FileStatus status)
{
- Debug.Assert(!path.Contains("fragments"));
+ Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
Debug.Assert(!path.EndsWith(".ignore",StringComparison.InvariantCultureIgnoreCase));
if (String.IsNullOrWhiteSpace(path))
public static readonly string PithosContainer = "pithos";
public static readonly string TrashContainer = "trash";
- public static readonly string FragmentsFolder = "fragments";
+ public static readonly string CacheFolder = ".pithos.cache";
}
}