Ejemplo n.º 1
0
        protected override async Task OnDeleteDirectoriesAsync(FilePath[] localPaths, bool force, ProgressMonitor monitor, bool keepLocal)
        {
            foreach (string path in localPaths)
            {
                if (!keepLocal)
                {
                    FileService.AssertCanDeleteDirectory(path, RootPath);
                }

                if (await IsVersionedAsync(path, monitor.CancellationToken).ConfigureAwait(false))
                {
                    string newPath = String.Empty;
                    if (keepLocal)
                    {
                        newPath = FileService.CreateTempDirectory();
                        FileService.CopyDirectory(path, newPath);
                    }
                    try {
                        Svn.Delete(path, force, monitor);
                    } finally {
                        if (keepLocal)
                        {
                            FileService.MoveDirectory(newPath, path);
                        }
                    }
                }
                else
                {
                    if (keepLocal)
                    {
                        foreach (var info in await GetDirectoryVersionInfoAsync(path, false, true, monitor.CancellationToken).ConfigureAwait(false))
                        {
                            if (info != null && info.HasLocalChange(VersionStatus.ScheduledAdd))
                            {
                                // Revert the add command
                                await RevertAsync(path, false, monitor).ConfigureAwait(false);
                            }
                        }
                    }
                    else
                    {
                        Directory.Delete(path, true);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteDirectoriesAsync(FilePath[] localPaths, bool force, ProgressMonitor monitor, bool keepLocal = true)
        {
            FileUpdateEventArgs args = new FileUpdateEventArgs();
            var metadata             = new DeleteMetadata(VersionControlSystem)
            {
                PathsCount = localPaths.Length, Force = force, KeepLocal = keepLocal
            };

            using (var tracker = Instrumentation.DeleteCounter.BeginTiming(metadata, monitor.CancellationToken)) {
                try {
                    await OnDeleteDirectoriesAsync(localPaths, force, monitor, keepLocal);

                    foreach (var path in localPaths)
                    {
                        args.Add(new FileUpdateEventInfo(this, path, true));
                    }
                } catch (Exception e) {
                    LoggingService.LogError("Failed to delete directory", e);
                    metadata.SetFailure();
                    if (!keepLocal)
                    {
                        try {
                            foreach (var path in localPaths)
                            {
                                FileService.AssertCanDeleteDirectory(path, RootPath);
                                Directory.Delete(path, true);
                            }
                        } catch (Exception e2) {
                            LoggingService.LogInternalError(e2);
                        }
                    }
                }
            }
            ClearCachedVersionInfo(localPaths);
            if (args.Any())
            {
                VersionControlService.NotifyFileStatusChanged(args);
            }
        }
Ejemplo n.º 3
0
 public void CantDeleteSystemFolders()
 {
     FileService.AssertCanDeleteDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
     FileService.AssertCanDeleteDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
     FileService.AssertCanDeleteDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
 }
Ejemplo n.º 4
0
        public void CantDeleteRoot()
        {
            string root = Platform.IsWindows ? "C:" : "/";

            FileService.AssertCanDeleteDirectory(root);
        }
Ejemplo n.º 5
0
 public void CanDeleteFolderWithBaseCheckWorks(string path, string requiredParentDirectory, bool canDeleteParent = true)
 {
     FileService.AssertCanDeleteDirectory(path, requiredParentDirectory, canDeleteParent);
 }