diff --git a/package/src/imports/directory.rs b/package/src/imports/directory.rs index d9f5be5868..5b6d0f40cf 100644 --- a/package/src/imports/directory.rs +++ b/package/src/imports/directory.rs @@ -46,4 +46,20 @@ impl ImportsDirectory { Ok(()) } + + /// Removes an imported package in the imports directory at the provided path. + pub fn remove_import(path: &PathBuf, package_name: &str) -> Result<(), ImportsDirectoryError> { + let mut path = path.to_owned(); + if path.is_dir() && !path.ends_with(IMPORTS_DIRECTORY_NAME) { + path.push(PathBuf::from(IMPORTS_DIRECTORY_NAME)); + } + + path.push(PathBuf::from(package_name)); + + if path.is_dir() && path.exists() { + fs::remove_dir_all(&path).map_err(ImportsDirectoryError::Removing)?; + } + + Ok(()) + } } diff --git a/package/src/lib.rs b/package/src/lib.rs index 0b2909f31a..0a7d6bc37d 100644 --- a/package/src/lib.rs +++ b/package/src/lib.rs @@ -36,4 +36,9 @@ impl LeoPackage { pub fn initialize(package_name: &str, is_lib: bool, path: &PathBuf) -> Result<(), PackageError> { package::Package::initialize(package_name, is_lib, path) } + + /// Removes an imported Leo package + pub fn remove_imported_package(package_name: &str, path: &PathBuf) -> Result<(), PackageError> { + package::Package::remove_imported_package(package_name, path) + } } diff --git a/package/src/package.rs b/package/src/package.rs index 595d81f860..d5b1b7609f 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -1,5 +1,22 @@ +// Copyright (C) 2019-2020 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + use crate::{ errors::PackageError, + imports::ImportsDirectory, inputs::{InputFile, InputsDirectory, StateFile}, root::{Gitignore, Manifest, README}, source::{LibraryFile, MainFile, SourceDirectory}, @@ -167,7 +184,7 @@ impl Package { } /// Removes the package at the given path - pub fn remove_package(_package_name: &str) -> Result<(), PackageError> { - unimplemented!() + pub fn remove_imported_package(package_name: &str, path: &PathBuf) -> Result<(), PackageError> { + Ok(ImportsDirectory::remove_import(path, package_name)?) } }