Skip to content
Merged
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
146 changes: 0 additions & 146 deletions .credo.exs

This file was deleted.

4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
43 changes: 14 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ jobs:
- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: "23.0"
elixir-version: "1.11.2"
otp-version: "25.0"
elixir-version: "1.14.2"

- name: Install dependencies
run: mix deps.get

# TODO: Enable in next release
#
# At the moment, we still have pending PRs etc.
# and introducing auto-formatting now would cause
# a ton of conflicts.
#
# - name: Check mix format
# run: mix format --check-formatted
- name: Check mix format
run: mix format --check-formatted

- name: Compile with warnings as errors
run: mix compile --warnings-as-errors
Expand All @@ -41,8 +35,8 @@ jobs:
- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: "23.0"
elixir-version: "1.11.2"
otp-version: "25.0"
elixir-version: "1.14.2"

- name: Install dependencies
run: mix deps.get
Expand All @@ -57,27 +51,18 @@ jobs:
fail-fast: false
matrix:
include:
- erlang: "24.2"
elixir: "1.12.3"
os: "ubuntu-22.04"
- erlang: "24.2"
elixir: "1.13.4"
os: "ubuntu-22.04"
- erlang: "23.0"
elixir: "1.11.2"
os: "ubuntu-latest"
os: "ubuntu-20.04"
- erlang: "23.0"
elixir: "1.10.3"
os: "ubuntu-latest"
- erlang: "22.3"
elixir: "1.9.4"
os: "ubuntu-latest"
- erlang: "21.3"
elixir: "1.8.2"
os: "ubuntu-latest"
- erlang: "20.3.1"
elixir: "1.7.4"
os: "ubuntu-latest"
- erlang: "19.3"
elixir: "1.6.6"
os: "ubuntu-18.04"
- erlang: "18.3"
elixir: "1.5.3"
os: "ubuntu-18.04"
os: "ubuntu-20.04"

steps:
- uses: actions/checkout@v1
Expand Down
31 changes: 1 addition & 30 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :sshkit, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:sshkit, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
import Config
16 changes: 10 additions & 6 deletions lib/sshkit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ defmodule SSHKit do
target = Keyword.get(options, :as, Path.basename(source))

run = fn host ->
{:ok, res} = SSH.connect host.name, host.options, fn conn ->
SCP.upload(conn, source, target, options)
end
{:ok, res} =
SSH.connect(host.name, host.options, fn conn ->
SCP.upload(conn, source, target, options)
end)

res
end

Expand Down Expand Up @@ -403,9 +405,11 @@ defmodule SSHKit do
target = Keyword.get(options, :as, Path.basename(source))

run = fn host ->
{:ok, res} = SSH.connect host.name, host.options, fn conn ->
SCP.download(conn, source, target, options)
end
{:ok, res} =
SSH.connect(host.name, host.options, fn conn ->
SCP.download(conn, source, target, options)
end)

res
end

Expand Down
15 changes: 11 additions & 4 deletions lib/sshkit/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule SSHKit.Context do

import SSHKit.Utils

defstruct [hosts: [], env: nil, path: nil, umask: nil, user: nil, group: nil]
defstruct hosts: [], env: nil, path: nil, umask: nil, user: nil, group: nil

@doc """
Compiles an executable command string for running the given `command`
Expand All @@ -38,12 +38,19 @@ defmodule SSHKit.Context do
end

defp sudo(command, nil, nil), do: command
defp sudo(command, username, nil), do: "sudo -H -n -u #{username} -- sh -c #{shellquote(command)}"
defp sudo(command, nil, groupname), do: "sudo -H -n -g #{groupname} -- sh -c #{shellquote(command)}"
defp sudo(command, username, groupname), do: "sudo -H -n -u #{username} -g #{groupname} -- sh -c #{shellquote(command)}"

defp sudo(command, username, nil),
do: "sudo -H -n -u #{username} -- sh -c #{shellquote(command)}"

defp sudo(command, nil, groupname),
do: "sudo -H -n -g #{groupname} -- sh -c #{shellquote(command)}"

defp sudo(command, username, groupname),
do: "sudo -H -n -u #{username} -g #{groupname} -- sh -c #{shellquote(command)}"

defp export(command, nil), do: command
defp export(command, env) when env == %{}, do: command

defp export(command, env) do
exports = Enum.map_join(env, " ", fn {name, value} -> "#{name}=\"#{value}\"" end)
"(export #{exports} && #{command})"
Expand Down
17 changes: 14 additions & 3 deletions lib/sshkit/scp/download.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule SSHKit.SCP.Download do
@moduledoc false
@moduledoc """
Helper module used by SSHKit.SCP.download/4.
"""

require Bitwise

Expand Down Expand Up @@ -28,7 +30,7 @@ defmodule SSHKit.SCP.Download do

defp start(connection, source, target, options) do
timeout = Keyword.get(options, :timeout, :infinity)
map_cmd = Keyword.get(options, :map_cmd, &(&1))
map_cmd = Keyword.get(options, :map_cmd, & &1)
command = map_cmd.(Command.build(:download, source, options))
handler = connection_handler(options)

Expand All @@ -41,10 +43,13 @@ defmodule SSHKit.SCP.Download do
case message do
{:data, _, 0, data} ->
process_data(state, data, options)

{:exit_status, _, status} ->
exited(options, state, status)

{:eof, _} ->
eof(options, state)

{:closed, _} ->
closed(options, state)
end
Expand All @@ -55,6 +60,7 @@ defmodule SSHKit.SCP.Download do
case state do
{:next, path, stack, attrs, buffer} ->
next(options, path, stack, attrs, buffer <> data)

{:read, path, stack, attrs, buffer} ->
read(options, path, stack, attrs, buffer <> data)
end
Expand Down Expand Up @@ -193,7 +199,7 @@ defmodule SSHKit.SCP.Download do
atime = :calendar.gregorian_seconds_to_datetime(@epoch + atime)
mtime = :calendar.gregorian_seconds_to_datetime(@epoch + mtime)
{:ok, file_info} = File.stat(path)
:ok = File.write_stat(path, %{file_info| mtime: mtime, atime: atime}, [:posix])
:ok = File.write_stat(path, %{file_info | mtime: mtime, atime: atime}, [:posix])
end

@tfmt ~S"(T)(0|[1-9]\d*) (0|[1-9]\d{0,5}) (0|[1-9]\d*) (0|[1-9]\d{0,5})"
Expand All @@ -206,14 +212,19 @@ defmodule SSHKit.SCP.Download do
case Regex.run(@dfmt, value, capture: :all_but_first) do
["T", mtime, mtus, atime, atus] ->
{"T", dec(mtime), dec(mtus), dec(atime), dec(atus)}

[chr, _, _, name] when chr in ["C", "D"] and name in ["/", "..", "."] ->
nil

["C", mode, len, name] ->
{"C", oct(mode), dec(len), name}

["D", mode, len, name] ->
{"D", oct(mode), dec(len), name}

["E"] ->
{"E"}

nil ->
nil
end
Expand Down
Loading