# Unable to automatically install artifact

**URL:** https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984
**Category:** General Usage
**Created:** [December 17, 2020, 2:47pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984 "2020-12-17T14:47:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [December 17, 2020, 2:47pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/1 "2020-12-17T14:47:53Z")

</div>

I’m trying to setup an automatic julia artifact download for [brainflow](https://github.com/brainflow-dev/brainflow/tree/master/julia-package). However I am encountering a .tar unpacking error. Let me elaborate.

Here is my script to generate the artifact in a folder with an Artifacts.toml folder:

```julia
using SHA
using Pkg
using Pkg.Artifacts
using Tar

url = "https://github.com/brainflow-dev/brainflow/releases/download/3.7.2/compiled_libs.tar"
download_path = "$(tempname())-download.tar"
download(url, download_path)

brainflow_hash = create_artifact() do artifact_dir 
    Tar.extract(download_path, artifact_dir)
end

artifact_name = "brainflow"
artifacts_toml = abspath(joinpath(@ __DIR__ , "Artifacts.toml"))
Pkg.Artifacts.bind_artifact!(artifacts_toml, artifact_name, brainflow_hash, force=true)

# now the artifact already works
brainflow_artifact_path = artifact"brainflow"

# adding the download info
function file_hash(path)
    return open(path) do file
        bytes2hex(sha2_256(file))
    end
end
tar_hash_sha256 = file_hash(download_path)
Pkg.Artifacts.bind_artifact!(artifacts_toml, artifact_name, brainflow_hash; download_info=[(url, tar_hash_sha256)], force=true)

```

Now I remove the artifact and try to download it again, then I get an error:

```julia
julia> remove_artifact(brainflow_hash)
julia> brainflow_artifact_path = artifact"brainflow"
ERROR: Unable to automatically install 'brainflow' from 'C:\Users\matcox\Documents\Julia\Artifacts.toml'

```

Following this [discourse discussion on Artifacts](https://discourse.julialang.org/t/providing-artifacts-basics/35459/9) I tried to debug:

```julia
julia> download_artifact(brainflow_hash, url, tar_hash_sha256; verbose=true)
[ Info: No hash cache found
[ Info: Calculated hash 92bd7485de8ccbd19d27a9b203e8176806269415b1087c767bb36539efe063d9 for file C:\Users\matcox\AppData\Local\Temp\jl_A2FMwHFjeJ-download.tar
[ Info: Unpacking C:\Users\matcox\AppData\Local\Temp\jl_A2FMwHFjeJ-download.tar into C:\Users\matcox\.julia\artifacts\1681bc5c836c0465e02c42dce71db9572d723b6e...
false

```

So it goes wrong in `unpack`:

```julia
Pkg.PlatformEngines.unpack(download_path, brainflow_artifact_path; verbose=verbose)
ERROR: Could not unpack C:\Users\matcox\AppData\Local\Temp\jl_PJRsMp1PNn-download.tar into C:\Users\matcox\.julia\artifacts\1681bc5c836c0465e02c42dce71db9572d723b6e

```

unpack calls a command like such:

```julia
julia> excludelist = nothing # I confirmed this was indeed set to nothing inside unpack()
julia> cmd = Pkg.PlatformEngines.gen_unpack_cmd(download_path, brainflow_artifact_path, excludelist)
julia> run(cmd)
ERROR: failed process: Process(`'C:\Users\matcox\AppData\Local\Programs\Julia-1.5.1\bin\..\libexec\7z.exe' x 'C:\Users\matcox\AppData\Local\Temp\jl_PJRsMp1PNn-download.tar' -y -so`, ProcessExited(2)) [2]

```

I tried typing this line on the command line

```julia
C:\>C:\Users\matcox\AppData\Local\Programs\Julia-1.5.1\bin\..\libexec\7z.exe x C:\Users\matcox\AppData\Local\Temp\jl_PJRsMp1PNn-download.tar -y

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive for archives:
1 file, 36666880 bytes (35 MiB)

Extracting archive: C:\Users\matcox\AppData\Local\Temp\jl_PJRsMp1PNn-download.tar
--
Path = C:\Users\matcox\AppData\Local\Temp\jl_PJRsMp1PNn-download.tar
Type = tar
Physical Size = 36666880
Headers Size = 23040
Code Page = UTF-8

ERROR: Can not open output file : Access is denied. : .\BoardController.dll
ERROR: Can not open output file : Access is denied. : .\BoardController.lib
...

```

Now I’m stuck. Any help would be much appreciated. I’d really like to get automatic artifact deployment working.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [December 17, 2020, 2:50pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/2 "2020-12-17T14:50:44Z")

</div>

If you want to create artifacts yourself, I recommend using [`ArtifactUtils.jl`](https://github.com/simeonschaub/ArtifactUtils.jl). It’s a nicer interface than low-level `Pkg` commands, users often do some mistakes when calling them.

However in your case you seem to have some permissions issues 🤔

---

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [December 17, 2020, 2:58pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/3 "2020-12-17T14:58:50Z")

</div>

ArtifactUtils.jl looks great. I wish I’d known about it before 😉

Just to confirm, similar error here:

```julia
using ArtifactUtils, Pkg.Artifacts
add_artifact!(
                  "Artifacts.toml",
                  "brainflow",
                  "https://github.com/brainflow-dev/brainflow/releases/download/3.7.2/compiled_libs.tar",
                  force=true,
              )
ERROR: Could not unpack C:\Users\matcox\AppData\Local\Temp\jl_h0ifO0k6hB into C:\Users\matcox\.julia\artifacts\jl_4t8KRo

```

---

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [December 17, 2020, 3:00pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/4 "2020-12-17T15:00:59Z")

</div>

> [@giordano](#):
>
> However in your case you seem to have some permissions issues

For your info, I’m on a company laptop which has no windows admin rights. However, this is the first time I encounter permission issues with unpacking files.

I’m a little sad, because `Tar.extract` works perfectly fine.

---

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [December 18, 2020, 10:59am UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/5 "2020-12-18T10:59:20Z")

</div>

Someone else with admin rights got the same unpack error on Windows: [https://github.com/brainflow-dev/brainflow/issues/150#issuecomment-738496467](https://github.com/brainflow-dev/brainflow/issues/150#issuecomment-738496467)

Should I create an issue somewhere?

---

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [December 21, 2020, 2:35pm UTC](https://discourse.julialang.org/t/unable-to-automatically-install-artifact/51984/6 "2020-12-21T14:35:27Z")

</div>

I’ve solved the issue for now by writing my own custom artifact download function that uses `Tar.extract()`. It feels somewhat imperfect.

However, it also gave me the opportunity to add a developer feature to the package: to optionally use a custom compiled library in a fixed location. This was requested by the package owner. I would not know how to easily enable this with artifacts. I believe artifacts are there to simplify the life of users who are unaware of the fact that external libraries are used.
