private void RemovedFailedPackageDownloads() { var pattern = "*" + NuGetPackageDownloader.DownloadingExtension; if (fileSystem.DirectoryExists(PackageDownloaderUtils.RootDirectory)) { var toDelete = fileSystem.EnumerateFilesRecursively(PackageDownloaderUtils.RootDirectory, pattern) .Where(f => fileSystem.GetCreationTime(f) <= DateTime.Now.AddDays(-1)) .ToArray(); foreach (var file in toDelete) { Log.Verbose($"Removing the failed to download file {file}"); fileSystem.DeleteFile(file, FailureOptions.IgnoreFailure); } } }
public FileLock ReadLock(string lockFilePath) { try { using (var stream = fileSystem.OpenFileExclusively(lockFilePath, FileMode.Open, FileAccess.Read)) { using (var streamReader = new StreamReader(stream)) { var obj = JObject.Load(new JsonTextReader(streamReader)); var lockContent = new FileLock { ProcessId = obj["ProcessId"].ToObject <long>(), ProcessName = obj["ProcessName"].ToString(), Timestamp = obj["Timestamp"].ToObject <long>(), ThreadId = obj["ThreadId"].ToObject <int>() }; if (lockContent.BelongsToCurrentProcessAndThread()) { return(lockContent); } return(new OtherProcessOwnsFileLock(lockContent)); } } } catch (FileNotFoundException) { return(new MissingFileLock()); } catch (IOException) { return(new OtherProcessHasExclusiveLockOnFileLock()); } catch (JsonReaderException) { return(new UnableToDeserialiseLockFile(fileSystem.GetCreationTime(lockFilePath))); } catch (Exception) //We have no idea what went wrong - reacquire this lock { return(new OtherProcessHasExclusiveLockOnFileLock()); } }