Skip to content

feat(install.sh): sudo {mkdir|cp} if necessary #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/fpm/installer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,17 @@ subroutine install(self, source, destination, error)
end if
end if

call self%run(self%copy//' "'//source//'" "'//install_dest//'"', error)

block
integer write_permission_stat

call execute_command_line("test -w " // install_dest, exitstat=write_permission_stat)
associate(sudo_if_needed => merge(" ","sudo ", write_permission_stat==0))
call self%run(sudo_if_needed // self%copy//' "'//source//'" "'//install_dest//'"', error)
end associate
end block


if (allocated(error)) return

end subroutine install
Expand Down
8 changes: 6 additions & 2 deletions src/fpm_filesystem.f90
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,12 @@ subroutine mkdir(dir)
select case (get_os_type())
case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD)
call execute_command_line('mkdir -p ' // dir, exitstat=stat)
write (*, '(" + ",2a)') 'mkdir -p ' // dir

if (stat/=0) then
call execute_command_line('sudo mkdir -p ' // dir, exitstat=stat)
write (*, '(" + ",2a)') 'sudo mkdir -p ' // dir
else
write (*, '(" + ",2a)') 'mkdir -p ' // dir
end if
case (OS_WINDOWS)
call execute_command_line("mkdir " // windows_path(dir), exitstat=stat)
write (*, '(" + ",2a)') 'mkdir ' // windows_path(dir)
Expand Down