From ccdd192fc69458ba1978a1613e797351708fc885 Mon Sep 17 00:00:00 2001 From: Joyce Babu Date: Tue, 28 Feb 2017 01:57:06 +0530 Subject: [PATCH] Fix 'mkdir File::Path: Permission denied' error Fixes the error mkdir File::Path: Permission denied when running as non - root user --- lib/Rex/Repositorio/Repository/Apt.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Rex/Repositorio/Repository/Apt.pm b/lib/Rex/Repositorio/Repository/Apt.pm index a8204d4..9c7c528 100644 --- a/lib/Rex/Repositorio/Repository/Apt.pm +++ b/lib/Rex/Repositorio/Repository/Apt.pm @@ -13,6 +13,7 @@ use Data::Dumper; use Digest::SHA; use Carp; use Params::Validate qw(:all); +use File::Path qw(make_path); use File::Spec; use IO::All; @@ -417,9 +418,19 @@ sub init { my $desc = $self->repo->{description} || "$component repository"; my $repo_dir = $self->app->get_repo_dir( repo => $self->repo->{name} ); + my @repodata_paths = (File::Spec->catdir($repo_dir,'dists',$dist,$component,"binary-$arch"), File::Spec->catdir($repo_dir,'pool',$dist,$component)); + + for my $repodata_path (@repodata_paths) { + $self->app->logger->debug("init: repodata_path: ${repodata_path}"); + unless (-d $repodata_path) { + $self->app->logger->debug("init: make_path: ${repodata_path}"); + my $make_path_error; + unless (make_path($repodata_path)) { + $self->app->logger->log_and_croak(level => 'error', message => "init: unable to create path: ${repodata_path}"); + } + } + } - File::Path->make_path(File::Spec->catdir($repo_dir,'dists',$dist,$component,"binary-$arch")); - File::Path->make_path(File::Spec->catdir($repo_dir,'pool',$dist,$component)); my $aptftp = io("$repo_dir/aptftp.conf"); my $aptgenerate = io("$repo_dir/aptgenerate.conf");