-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename release server -> update server
- Loading branch information
1 parent
cf395b2
commit d317665
Showing
15 changed files
with
511 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
defmodule Peridiod.BundleOverride do | ||
use Peridiod.Cache.Helpers, cache_path: "override" | ||
|
||
alias Peridiod.{BundleOverride, Bundle} | ||
|
||
require Logger | ||
|
||
defstruct prn: nil, | ||
bundle: nil | ||
|
||
@type t() :: %__MODULE__{ | ||
prn: String.t(), | ||
bundle: Bundle.t() | ||
} | ||
|
||
defimpl Jason.Encoder, for: BundleOverride do | ||
def encode(%BundleOverride{} = override_metadata, opts) do | ||
override_metadata | ||
|> Map.take([:prn, :name, :version_requirement]) | ||
|> Map.put(:bundle_prn, override_metadata.bundle.prn) | ||
|> Jason.Encode.map(opts) | ||
end | ||
end | ||
|
||
def metadata_from_cache(cache_pid, override_prn) do | ||
manifest_file = Path.join([@cache_path, override_prn, "manifest"]) | ||
|
||
with {:ok, json} <- Cache.read(cache_pid, manifest_file), | ||
{:ok, map} <- Jason.decode(json) do | ||
bundle_metadata = | ||
case Bundle.metadata_from_cache(cache_pid, map["bundle_prn"]) do | ||
{:ok, bundle_metadata} -> bundle_metadata | ||
_ -> nil | ||
end | ||
|
||
map = Map.put(map, "bundle", bundle_metadata) | ||
{:ok, metadata_from_map(map)} | ||
end | ||
end | ||
|
||
def metadata_from_map(override_metadata) do | ||
%__MODULE__{ | ||
prn: override_metadata["prn"], | ||
bundle: override_metadata["bundle"] | ||
} | ||
end | ||
|
||
@doc """ | ||
Recursively parse a release manifest into structs | ||
""" | ||
@spec metadata_from_manifest(map()) :: {:ok, t()} | ||
def metadata_from_manifest( | ||
%{ | ||
"bundle_override" => override_metadata | ||
} = manifest | ||
) do | ||
bundle = | ||
case Bundle.metadata_from_manifest(manifest) do | ||
{:ok, bundle} -> | ||
bundle | ||
|
||
error -> | ||
Logger.error("Error loading bundle from manifest: #{inspect(error)}") | ||
nil | ||
end | ||
|
||
{:ok, | ||
%__MODULE__{ | ||
prn: override_metadata["prn"], | ||
bundle: bundle | ||
}} | ||
end | ||
|
||
def metadata_to_cache( | ||
cache_pid \\ Cache, | ||
%__MODULE__{prn: override_prn, bundle: bundle} = override_metadata | ||
) do | ||
override_json = Jason.encode!(override_metadata) | ||
manifest_file = Path.join([@cache_path, override_prn, "manifest"]) | ||
|
||
with :ok <- Cache.write(cache_pid, manifest_file, override_json), | ||
:ok <- Bundle.metadata_to_cache(cache_pid, bundle) do | ||
:ok | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Peridiod.Cache.Helpers do | ||
defmacro __using__(opts) do | ||
quote do | ||
import Peridiod.Utils, only: [stamp_utc_now: 0] | ||
alias Peridiod.Cache | ||
|
||
@cache_path unquote(opts[:cache_path]) | ||
@cache_file unquote(opts[:cache_file]) | ||
@stamp_cached ".stamp_cached" | ||
@stamp_installed ".stamp_installed" | ||
|
||
def cache_path(%{prn: prn}) do | ||
cache_path(prn) | ||
end | ||
|
||
def cache_path(prn) when is_binary(prn) do | ||
Path.join([@cache_path, prn]) | ||
end | ||
|
||
def cached?(cache_pid \\ Cache, metadata) do | ||
stamp_file = Path.join([cache_path(metadata), @stamp_cached]) | ||
Cache.exists?(cache_pid, stamp_file) | ||
end | ||
|
||
def installed?(cache_pid \\ Cache, metadata) do | ||
stamp_file = Path.join([cache_path(metadata), @stamp_installed]) | ||
Cache.exists?(cache_pid, stamp_file) | ||
end | ||
|
||
def stamp_cached(cache_pid \\ Cache, metadata) do | ||
stamp_file = Path.join([cache_path(metadata), @stamp_cached]) | ||
Cache.write(cache_pid, stamp_file, stamp_utc_now()) | ||
end | ||
|
||
def stamp_installed(cache_pid \\ Cache, metadata) do | ||
stamp_file = Path.join([cache_path(metadata), @stamp_installed]) | ||
Cache.write(cache_pid, stamp_file, stamp_utc_now()) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.