File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 11import { assertEquals } from "@std/assert/equals"
22import { join } from "@std/path/join"
3- import { annexRelativePath , hashDirLower , hashDirMixed } from "./annex.ts"
3+ import {
4+ annexKeyRegex ,
5+ annexRelativePath ,
6+ hashDirLower ,
7+ hashDirMixed ,
8+ } from "./annex.ts"
49
510Deno . test ( "annexRelativePath() returns appropriate paths" , ( ) => {
611 assertEquals (
@@ -26,3 +31,28 @@ Deno.test("hashDirMixed() returns the correct key prefix", async () => {
2631 [ "Xk" , "Mx" ] ,
2732 )
2833} )
34+
35+ Deno . test ( "annexKeyRegex matches valid keys" , ( ) => {
36+ // Typical key
37+ assertEquals (
38+ "SHA256E-s311112--c3527d7944a9619afb57863a34e6af7ec3fe4f108e56c860d9e700699ff806fb.nii.gz"
39+ . match ( annexKeyRegex ) ?. slice ( 1 , 5 ) ,
40+ [
41+ "SHA256E" ,
42+ "311112" ,
43+ "c3527d7944a9619afb57863a34e6af7ec3fe4f108e56c860d9e700699ff806fb" ,
44+ ".nii.gz" ,
45+ ] ,
46+ )
47+ // Filenames with other characters
48+ assertEquals (
49+ "SHA256E-s6148--e53302cf7b8beb7c5b908c070618bb11e2590719465d0869522716ecc2cfecd8.DS_Store"
50+ . match ( annexKeyRegex ) ?. slice ( 1 , 5 ) ,
51+ [
52+ "SHA256E" ,
53+ "6148" ,
54+ "e53302cf7b8beb7c5b908c070618bb11e2590719465d0869522716ecc2cfecd8" ,
55+ ".DS_Store" ,
56+ ] ,
57+ )
58+ } )
Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ const textDecoder = new TextDecoder("utf-8")
2323const computeHashMD5 = await createMD5 ( )
2424const computeHashSHA256 = await createSHA256 ( )
2525
26+ /**
27+ * Matches valid git-annex keys
28+ * Example input: SHA256E-s311112--c3527d7944a9619afb57863a34e6af7ec3fe4f108e56c860d9e700699ff806fb.nii.gz
29+ * Group 1: SHA256E
30+ * Group 2: 311112
31+ * Group 3: c3527d7944a9619afb57863a34e6af7ec3fe4f108e56c860d9e700699ff806fb
32+ * Group 4: .nii.gz
33+ */
34+ export const annexKeyRegex = / ^ ( [ A - Z 0 - 9 ] + ) - s ( \d + ) - - ( [ 0 - 9 a - f A - F ] + ) ( \. [ \w \- . ] * ) ? /
35+
2636/**
2737 * git-annex hashDirLower implementation based on https://git-annex.branchable.com/internals/hashing/
2838 * Compute the directory path from a git-annex filename
@@ -196,7 +206,7 @@ export async function getAnnexKeys(
196206 // Check that annexKey conforms to the git-annex key format
197207 // Other symlinks are allowed but may be rejected on push if they point outside of the repo
198208 if (
199- annexKey . match ( / ^ [ A - Z 0 - 9 ] + - s \d + - - [ 0 - 9 a - f A - F ] + ( \. [ a - z A - Z 0 - 9 . ] * ) ? $ / )
209+ annexKey . match ( annexKeyRegex )
200210 ) {
201211 logger . info ( `Found key "${ annexKey } " in HEAD.` )
202212 annexKeys [ annexKey ] = filepath
You can’t perform that action at this time.
0 commit comments