Skip to content

Commit

Permalink
Merge pull request #5943 from kit-ty-kate/allow-unpadded-base64
Browse files Browse the repository at this point in the history
Allow to parse opam 2.1 switch import files containing extra-files
  • Loading branch information
kit-ty-kate committed May 8, 2024
2 parents 3159a67 + b22db51 commit 5c4c1a4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Expand Up @@ -28,6 +28,7 @@ users)
## Remove

## Switch
* Allow to parse opam 2.1 switch import files containing extra-files [#5943 @kit-ty-kate - fix #5941]

## Config

Expand Down
4 changes: 2 additions & 2 deletions src/client/opamSwitchCommand.ml
Expand Up @@ -398,7 +398,7 @@ let import_t ?ask importfile t =
OpamPath.Switch.extra_files_dir t.switch_global.root t.switch
in
OpamHash.Map.iter (fun hash content ->
let value = Base64.decode_exn content in
let value = Base64.decode_exn ~pad:false content in
let my = OpamHash.compute_from_string ~kind:(OpamHash.kind hash) value in
if OpamHash.contents my = OpamHash.contents hash then
let dst =
Expand Down Expand Up @@ -629,7 +629,7 @@ let export rt ?(freeze=false) ?(full=false)
List.fold_left (fun (hmap,err) (file, base, hash) ->
if OpamFilename.exists file &&
OpamHash.check_file (OpamFilename.to_string file) hash then
let value = Base64.encode_string (OpamFilename.read file) in
let value = Base64.encode_string ~pad:false (OpamFilename.read file) in
OpamHash.Map.add hash value hmap, err
else hmap, base::err)
(hmap,[]) files
Expand Down
79 changes: 79 additions & 0 deletions tests/reftests/switch-import.test
Expand Up @@ -270,3 +270,82 @@ The following actions will be performed:
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed c.1
Done.
### # Test that 2.1 unpadded export files are well imported
### opam switch create padded-base64-extra-files --empty
### <padded-base64-extra-files.xp>
extra-files: ["md5=d8e8fca2dc0f896fd7cb4cb0031ba249" "dGVzdAo="]
opam-version: "2.0"
roots: ["test.dev"]
installed: ["test.dev"]
pinned: "test.dev"
package "test" {
opam-version: "2.0"
version: "dev"
extra-files: ["test" "md5=d8e8fca2dc0f896fd7cb4cb0031ba249"]
install: ["cp" "test" "%{prefix}%/test"]
}
### opam switch import padded-base64-extra-files.xp
The following actions will be performed:
=== install 1 package
- install test dev (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed test.dev
Done.
### cat OPAM/padded-base64-extra-files/test
test
### opam switch create unpadded-base64-extra-files --empty
### <unpadded-base64-extra-files.xp>
extra-files: ["md5=d8e8fca2dc0f896fd7cb4cb0031ba249" "dGVzdAo"]
opam-version: "2.0"
roots: ["test.dev"]
installed: ["test.dev"]
pinned: "test.dev"
package "test" {
opam-version: "2.0"
version: "dev"
extra-files: ["test" "md5=d8e8fca2dc0f896fd7cb4cb0031ba249"]
install: ["cp" "test" "%{prefix}%/test"]
}
### opam switch import unpadded-base64-extra-files.xp
The following actions will be performed:
=== install 1 package
- install test dev (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed test.dev
Done.
### cat OPAM/unpadded-base64-extra-files/test
test
### <export-extra-files/test.opam>
opam-version: "2.0"
extra-files: ["test" "md5=d8e8fca2dc0f896fd7cb4cb0031ba249"]
### <export-extra-files/files/test>
test
### opam switch create export-extra-files --empty
### opam pin ./export-extra-files
test is now pinned to file://${BASEDIR}/export-extra-files (version 1)

The following actions will be performed:
=== install 1 package
- install test 1 (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved test.1 (file://${BASEDIR}/export-extra-files)
-> installed test.1
Done.
### opam switch export extra-files.xp
### opam-cat ./extra-files.xp
extra-files: ["md5=d8e8fca2dc0f896fd7cb4cb0031ba249" "dGVzdAo"]
installed: ["test.1"]
opam-version: "2.0"
pinned: "test.1"
roots: ["test.1"]
package "test" {
opam-version: "2.0"
version: "1"
extra-files: ["test" "md5=d8e8fca2dc0f896fd7cb4cb0031ba249"]
url {
src: "file://${BASEDIR}/export-extra-files"
}
}

0 comments on commit 5c4c1a4

Please sign in to comment.