Skip to content

Commit

Permalink
Fix base package error for self-contained apps
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
j8r committed Mar 22, 2020
1 parent eb5282c commit 786b9e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion spec/cli_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ describe DPPM::CLI do
end
end

it "uninstalls DPPM" do
it "uninstalls DPPM and removes applications" do
spec_with_tempdir do |prefix|
install_dppm prefix
add_application prefix_path: prefix

DPPM::CLI.uninstall_dppm(
no_confirm: true,
Expand Down
4 changes: 2 additions & 2 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ module DPPM::CLI
root_prefix.delete
raise Error.new "DPPM installation failed, #{root_prefix.path} deleted", ex
end
dppm_package.create_global_bin_symlinks(force: true) if Process.root?
app.pkg?.try &.create_global_bin_symlinks(force: true) if Process.root?
Logger.info "DPPM installation complete", "you can now manage applications with the `#{Process.root? ? "dppm" : dppm_bin_path}` command"
end

Expand All @@ -425,7 +425,7 @@ module DPPM::CLI
root_prefix.each_app do |app|
app.delete(confirmation: !no_confirm, preserve_database: false, keep_user_group: false) do
if no_confirm || CLI.confirm_prompt
app.pkg.delete_global_bin_symlinks
app.pkg?.try &.delete_global_bin_symlinks
true
end
end
Expand Down
14 changes: 12 additions & 2 deletions src/prefix/app.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct DPPM::Prefix::App
getter log_file_output : Path { logs_path / ("output" + LOG_EXTENSION) }
getter log_file_error : Path { logs_path / ("error" + LOG_EXTENSION) }
getter webserver_sites_path : Path { conf_path / "sites" }
# The application is self-contained.
getter? contained : Bool { real_app_path == app_path }

protected def initialize(@prefix : Prefix, @name : String, pkg_file : PkgFile? = nil, @pkg : Pkg? = nil)
Utils.ascii_alphanumeric_dash? name
Expand Down Expand Up @@ -38,8 +40,16 @@ struct DPPM::Prefix::App
conf_path / ".password"
end

getter pkg : Pkg do
Pkg.new @prefix, File.basename(File.dirname(File.real_path(app_path.to_s))), nil, @pkg_file
# Base `Pkg` package of this application.
def pkg : Pkg
pkg? || raise "Cannot get the base package - the application `#{@name}` is self-contained."
end

# :ditto:
getter? pkg : Pkg? do
if !contained?
Pkg.new @prefix, real_app_path.basename, nil, @pkg_file
end
end

getter exec : Hash(String, String) do
Expand Down

0 comments on commit 786b9e6

Please sign in to comment.