Skip to content

Commit 25cb84c

Browse files
committed
fix for items with spaces
1 parent f4c09d9 commit 25cb84c

File tree

10 files changed

+99
-65
lines changed

10 files changed

+99
-65
lines changed

.ci/tests_entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
TESTS=`pwd`/tests/cls
3+
TESTS=`pwd`/tests/src
44

55
iris start $ISC_PACKAGE_INSTANCENAME quietly EmergencyID=admin,sys \
66

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN iris start $ISC_PACKAGE_INSTANCENAME quietly EmergencyID=admin,sys \
99
&& /bin/echo -e "admin\nsys\n" \
1010
'do $system.OBJ.ImportDir("/opt/src/", "*.cls", "ck", , 1)\n' \
1111
'zn "USER"\n' \
12-
'set ^UnitTestRoot="/opt/tests/"\n' \
12+
'set ^UnitTestRoot="/opt/tests/src/"\n' \
1313
'do $system.OBJ.SetQualifiers("/nodelete")\n' \
1414
'halt\n' \
1515
| iris session $ISC_PACKAGE_INSTANCENAME \

src/cls/%zUtils/FileBinaryTar.cls

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Method FindPath(pPath As %String = "", Output found As FileBinaryTar) As %Status
119119
set pPath = $tr(pPath, "\", "/")
120120
set tmp = ..GetAt($p(pPath, "/"))
121121
if '$isobject(tmp) {
122-
return $$$ERROR($$$GeneralError, "not found")
122+
return $$$ERROR($$$GeneralError, "Path '"_pPath_"' not found")
123123
}
124124
if $l(pPath, "/")>1 {
125125
return tmp.FindPath($p(pPath, "/", 2, *), .found)
@@ -177,8 +177,16 @@ ClassMethod ExtractStream(aFileStream As %Stream.Object) As FileBinaryTar
177177
set longLink4Name=""
178178
set longLink4Link=""
179179
do {
180+
set repeat=0
180181
set tHeader=aFileStream.Read(blockSize)
181182
do tFile.ParseHeader(tHeader)
183+
if tFile.name="./" {
184+
set repeat=1
185+
continue
186+
}
187+
If ($EXTRACT(tFile.name, 1, 2) = "./") {
188+
Set tFile.name = $EXTRACT(tFile.name, 3, *)
189+
}
182190
quit:tFile.name=""
183191
set $EXTRACT(tHeader, 149, 156) = $JUSTIFY("", 8)
184192
set chksumExpected = $zcrc(tHeader, 0)
@@ -322,7 +330,7 @@ ClassMethod ConstructTar(Path As %String, RelativeTo As %String, archive As %Str
322330
set obj.chksum = $ZCRC(header, 0)
323331
set header = obj.ConstructHeader()
324332
}
325-
333+
326334
if (size > 0) {
327335
do archive.Write(header)
328336
set fs = ##class(%Stream.FileBinary).%New()
@@ -362,8 +370,11 @@ Method ConstructHeader() As %Binary [ CodeMode = objectgenerator, Internal ]
362370
Do %code.WriteLine($char(9)_"Set tVal = i%"_tProp.Name)
363371
If (tProp.Parameters.GetAt("TRUNCATE")) {
364372
Do %code.WriteLine($char(9)_"Set tVal = $extract(tVal, 1, "_(tLen-1)_")")
365-
Do %code.WriteLine($char(9)_"Set tVal = tVal _ $justify("""", "_(tLen)_" - $length(tVal))")
366-
Do %code.WriteLine($char(9)_"Set tVal = $translate(tVal, $char(32), $char(0))")
373+
#; Do %code.WriteLine($char(9)_"Set tVal = tVal _ $justify("""", "_(tLen)_" - $length(tVal))")
374+
#; Do %code.WriteLine($char(9)_"Set tVal = $translate(tVal, $char(32), $char(0))")
375+
Do %code.WriteLine($char(9)_"Set tPadding = $justify("""", "_(tLen)_" - $length(tVal))")
376+
Do %code.WriteLine($char(9)_"Set tPadding = $translate(tPadding, $char(32), $char(0))")
377+
Do %code.WriteLine($char(9)_"Set tVal = tVal _ tPadding")
367378
} else {
368379
Do %code.WriteLine($char(9)_"Set tVal = tVal _ $translate($justify("""", "_(tLen)_" - $length(tVal)), $char(32), $char(0))")
369380
}

tests/cls/UnitTests/FileBinaryTar.cls

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test content for file with spaces
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test file in folder with spaces
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test content for file with spaces

tests/data/test.tgz

-233 Bytes
Binary file not shown.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Class UnitTests.FileBinaryTar Extends %UnitTest.TestCase
2+
{
3+
4+
/// Path to examples files
5+
Property Path As %String;
6+
7+
Method OnBeforeAllTests() As %Status
8+
{
9+
set ..Path = ##class(%File).NormalizeDirectory("data", ##class(%File).ParentDirectoryName(^UnitTestRoot))
10+
Quit $$$OK
11+
}
12+
13+
/// Testing extract archive
14+
Method TestExtract()
15+
{
16+
set fileName = ##class(%File).NormalizeFilename("test.tgz", ##class(%File).ParentDirectoryName(..Path))
17+
set extracted = ##class(%zUtils.FileBinaryTar).ExtractFile(fileName)
18+
do ..CheckExtracted(extracted)
19+
}
20+
21+
Method CompareFolders(pOriginal As %String, pNew As %String)
22+
{
23+
Set tRS = ##class(%File).FileSetFunc(pOriginal)
24+
While tRS.%Next() {
25+
If tRS.Type="D" {
26+
Do ..CompareFolders(tRS.Name, ##class(%File).NormalizeDirectory(tRS.ItemName, pNew))
27+
}
28+
ElseIf tRS.Type="F" {
29+
set tName = tRS.ItemName
30+
If ($LISTFIND($LISTBUILD("tar", "tgz"), $$$lcase($PIECE(tName, ".", *)))) {
31+
CONTINUE
32+
}
33+
set tNewName = ##class(%File).NormalizeDirectory(pNew) _ tName
34+
if $$$AssertTrue(##class(%File).Exists(tNewName), tNewName) {
35+
do $$$AssertEquals(##class(%File).GetFileSize(tNewName), ##class(%File).GetFileSize(tRS.Name))
36+
}
37+
}
38+
}
39+
}
40+
41+
Method CheckExtracted(extracted As %zUtils.FileBinaryTar) [ Internal ]
42+
{
43+
do $$$AssertTrue($isobject(extracted), "Extract successful")
44+
do $$$AssertStatusOK(extracted.FindPath("folder", .folder), "root folder")
45+
do $$$AssertStatusOK(extracted.FindPath("folder/subfolder/test.txt", .file), "test.txt in the subfolder")
46+
if $$$AssertEquals(file.fileData.Read(), "test file in subfolder", "right content") {
47+
do $$$AssertStatusOK(folder.FindPath("test.txt", .file), "test.txt in the folder") }
48+
do $$$AssertEquals(file.fileData.Read(), "test file in folder", "right content")
49+
do $$$AssertStatusOK(folder.FindPath("file with spaces.txt", .file), "file with spaces.txt in the folder")
50+
do $$$AssertEquals(file.fileData.Read(), "test content for file with spaces", "right content")
51+
if $$$AssertStatusOK(extracted.FindPath("folder with spaces/test.txt", .file), "test.txt in the folder with spaces") {
52+
do $$$AssertEquals(file.fileData.Read(), "test file in folder with spaces", "right content") }
53+
if $$$AssertStatusOK(extracted.FindPath("folder with spaces/file with spaces.txt", .file), "file with spaces.txt in the folder with spaces") {
54+
do $$$AssertEquals(file.fileData.Read(), "test content for file with spaces", "right content") }
55+
56+
set tmpDir = $$$FileTempDir
57+
do $$$AssertStatusOK(extracted.ExtractTo(tmpDir))
58+
59+
Do ..CompareFolders(..Path, tmpDir)
60+
61+
do ##class(%File).RemoveDirectoryTree(tmpDir)
62+
}
63+
64+
/// Testing Compact some data to archive
65+
Method TestCompact()
66+
{
67+
set path = ##class(%File).NormalizeDirectory(..Path)
68+
set tmpFile = ##class(%File).TempFilename("tgz")
69+
set archive = ##class(%zUtils.FileBinaryTar).Compact(path, 0, tmpFile, path)
70+
do $$$AssertTrue(##class(%File).Exists(tmpFile), "New archive created")
71+
72+
do archive.Rewind()
73+
set extracted = ##class(%zUtils.FileBinaryTar).ExtractStream(archive)
74+
do ..CheckExtracted(extracted)
75+
#; Do ##class(%File).Delete(tmpFile)
76+
zw tmpFile
77+
}
78+
79+
}

tests/test.tgz

370 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)