public IActionResult CleanPackagesDirectory([FromBody] CleanPackagesDirectoryRequest request)
        {
            var uploadDirectory = Path.Combine(_hostingEnvironment.ContentRootPath, "packages");

            if (!string.IsNullOrWhiteSpace(request.SubDirectoryToDelete))
            {
                uploadDirectory = Path.Combine(uploadDirectory, request.SubDirectoryToDelete);
            }

            try
            {
                if (Directory.Exists(uploadDirectory))
                {
                    Directory.Delete(uploadDirectory, true);
                }
            }
            catch (IOException)
            {
                Thread.Sleep(1000);
                Directory.Delete(uploadDirectory, true);
            }

            Directory.CreateDirectory(uploadDirectory);

            return(Ok());
        }
Exemplo n.º 2
0
        public IActionResult CleanPackagesDirectory([FromBody] CleanPackagesDirectoryRequest request)
        {
            var uploadDirectory = Path.Combine(_hostingEnvironment.ContentRootPath, "Packages");

            if (!string.IsNullOrWhiteSpace(request.SubDirectoryToDelete))
            {
                var destDirPath = Path.GetFullPath(Path.Combine(uploadDirectory + Path.DirectorySeparatorChar));
                uploadDirectory = Path.GetFullPath(Path.Combine(uploadDirectory, request.SubDirectoryToDelete));

                if (!uploadDirectory.StartsWith(destDirPath))
                {
                    throw new HttpError(HttpStatusCode.Forbidden);
                }
            }

            try
            {
                if (Directory.Exists(uploadDirectory))
                {
                    Directory.Delete(uploadDirectory, true);
                }
            }
            catch (IOException)
            {
                Thread.Sleep(1000);
                Directory.Delete(uploadDirectory, true);
            }

            Directory.CreateDirectory(uploadDirectory);

            return(Ok());
        }
Exemplo n.º 3
0
 public async Task DeletePackagesAsync(CleanPackagesDirectoryRequest request)
 {
     await SendAsync(request);
 }