Skip to content

Commit

Permalink
#28 length of Path need to be less than 255
Browse files Browse the repository at this point in the history
  • Loading branch information
kazurayam committed Jun 30, 2020
1 parent e54148f commit cd09d0b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 23 deletions.
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'com.jfrog.bintray'

group = 'com.kazurayam'
archivesBaseName = 'Materials'
version = '0.77.1'
version = '0.77.2'


sourceCompatibility = '1.8'
Expand Down Expand Up @@ -107,9 +107,9 @@ test {
include '**/materials/*Spec.class'
include '**/materials/**/*Spec.class'

//exclude '**/ComparisonResultBundleSpec.class' // takes 145 sec
//exclude '**/ImageCollectionDifferSpec.class' // takes 110 sec
//exclude '**/stats/*Spec.class' // these specs take too long; include them only when necessary
exclude '**/ComparisonResultBundleSpec.class' // takes 145 sec
exclude '**/ImageCollectionDifferSpec.class' // takes 110 sec
exclude '**/stats/*Spec.class' // these specs take too long; include them only when necessary
finalizedBy jacocoTestReport
outputs.upToDateWhen {false}
}
Expand All @@ -123,14 +123,14 @@ task pinpoint(type: Test) {
//include "**/imagedifference/ComparisonResultBundleSpec.class"
//include "**/imagedifference/ComparisonResultSpec.class"
//include "**/imagedifference/imagedifference/EspionageSpec.class"
include "**/imagedifference/ImageCollectionDifferSpec.class"
//include "**/imagedifference/ImageCollectionDifferSpec.class"
//include "**/imagedifference/ImageDifferenceFilenameResolverCompactImplSpec.class"
//include "**/imagedifference/ImageDifferenceFilenameResolverDefaultImplSpec.class"
//include "**/imagedifference/ImageDifferenceSpec.class"
//include "**/impl/MaterialCoreImplSpec.class"
//include "**/impl/MaterialImplSpec.class"
include "**/impl/MaterialPairImpl.class"
//include "**/impl/MaterialRepositoryImplSpec.class"
//include "**/impl/MaterialPairImpl.class"
include "**/impl/MaterialRepositoryImplSpec.class"
//include "**/impl/MaterialStorageImplSpec.class"
//include "**/impl/TSuiteResultImplSpec.class"
//include "**/IndexerFactorySpec.class"
Expand Down Expand Up @@ -159,7 +159,7 @@ task pinpoint(type: Test) {
//include "**/stats/ImageDeltaStatsSpec.class"
//include "**/stats/MaterialStatsSpec.class"
//include "**/stats/StatsEntrySpec.class"
include "**/stats/StorageScannerSpec.class"
//include "**/stats/StorageScannerSpec.class"
//include "**/TCaseNameSpec.class"
//include "**/TCaseResultSpec.class"
//include "**/TExecutionProfileSpec.class"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.kazurayam.materials.impl

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneOffset
Expand All @@ -13,20 +12,14 @@ import org.slf4j.LoggerFactory
import com.kazurayam.materials.FileType
import com.kazurayam.materials.Helpers
import com.kazurayam.materials.Material
import com.kazurayam.materials.MaterialCore
import com.kazurayam.materials.MaterialRepository
import com.kazurayam.materials.TCaseName
import com.kazurayam.materials.TCaseResult
import com.kazurayam.materials.TSuiteName
import com.kazurayam.materials.TSuiteResult
import com.kazurayam.materials.TSuiteTimestamp
import com.kazurayam.materials.VisualTestingLogger
import com.kazurayam.materials.model.MaterialFileName
import com.kazurayam.materials.model.Suffix
import com.kazurayam.materials.repository.RepositoryRoot

import groovy.json.JsonOutput

/**
* A Material has a Path <TSuiteName>/<TSuiteTimestamp>/<TCaseName>/<subpath>/<MaterialFileName>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ final class MaterialRepositoryImpl implements MaterialRepository {
if (url.getPath() == null || url.getPath() == '') {
return resolveScreenshotPath(tCaseName, subPath, url)
}

String fileName = resolveFileNameByURLPathComponents(url, startingDepth, defaultName)


TSuiteResult tSuiteResult = getCurrentTSuiteResult()
if (tSuiteResult == null) {
throw new IllegalStateException("getCurrentTSuiteResult() returned null")
Expand All @@ -514,8 +512,24 @@ final class MaterialRepositoryImpl implements MaterialRepository {
tSuiteResult.addTCaseResult(tCaseResult)
}
Helpers.ensureDirs(tCaseResult.getTCaseDirectory())

Material material = new MaterialImpl(tCaseResult, tCaseResult.getTCaseDirectory().resolve(subPath).resolve(fileName))

String fileName = resolveFileNameByURLPathComponents(url, startingDepth, defaultName)
Material material = new MaterialImpl(tCaseResult,
tCaseResult.getTCaseDirectory().resolve(subPath).resolve(fileName))

// see https://github.com/kazurayam/Materials/issues/28
// We will check the absolute path length of the material file.
// Ff the length exceed 255, Windows path length limit, then shorten the file name
// by filtering '%26' (& URL encoded) and '%3D' (= URL encoded) to '' and
// recreate the material
if (material.getPath().toAbsolutePath().toString().length() > 255) {
fileName =
fileName.replace('%26', '')
.replace('%3D', '')
material = new MaterialImpl(tCaseResult,
tCaseResult.getTCaseDirectory().resolve(subPath).resolve(fileName))
}


//
Files.createDirectories(material.getPath().getParent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.kazurayam.materials.TExecutionProfile
import com.kazurayam.materials.TSuiteName
import com.kazurayam.materials.TSuiteResult
import com.kazurayam.materials.TSuiteResultId
import com.kazurayam.materials.TSuiteTimestamp
import com.kazurayam.materials.VisualTestingLogger
import com.kazurayam.materials.repository.RepositoryRoot
import org.slf4j.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,30 @@ class MaterialRepositoryImplSpec extends Specification {
then:
Files.exists(metadataBundle)
}


/**
def testResolveScreenshotPathByURLPathComponents_longQuery() {
setup:
Path casedir = workdir_.resolve('testResolveScreenshotPathByURLPathComponents_longQuery')
Helpers.copyDirectory(fixture_, casedir)
Path materialsDir = casedir.resolve('Materials')
MaterialRepositoryImpl mri = MaterialRepositoryImpl.newInstance(materialsDir)
mri.markAsCurrent('Test Suites/main/TS1',
'CURA_ProductionEnv', '20180530_130604')
TSuiteResult tsr = mri.ensureTSuiteResultPresent('Test Suites/main/TS1',
'CURA_ProductionEnv','20180530_130604')
when:
Path p = mri.resolveScreenshotPathByURLPathComponents('TC1',
new URL('https://my.home.net/gn/issueList.html' +
"?KEY00=VAL00&KEY01=VAL01&KEY02=VAL02&KEY03=VAL03&KEY04=VAL04" +
"&KEY05=VAL05"))
then:
p.toString().length() < 255

}



/**
MaterialRepositoryImpl DEBUG #resolveMaterialPath count=1
MaterialImpl DEBUG #getPath parentTCR_.getTCaseDirectory()=build\tmp\testOutput\MaterialRepositoryImplSpec\testResolveMaterialPath\Materials\TS1\20180530_130604\TC1
MaterialImpl DEBUG #getPath subpath_=..\..\..\..\..\..\..\..\..\
Expand Down Expand Up @@ -360,4 +381,24 @@ MaterialImpl DEBUG #getPath p=http%3A%2F%2Fdemoaut.katalon.com%2F.png
str.contains('}}')
}

def test_resolveFileNameByURLPathComponents_simple() {
setup:
Path casedir = workdir_.resolve('test_resolveFileNameByURLPathComponents_simple')
Helpers.copyDirectory(fixture_, casedir)
Path materialsDir = casedir.resolve('Materials')
MaterialRepositoryImpl mri = MaterialRepositoryImpl.newInstance(materialsDir)
mri.markAsCurrent('Test Suites/TS1',
'CURA_ProductionEnv', '20180810_140105')
def tsr = mri.ensureTSuiteResultPresent('Test Suites/TS1',
'CURA_ProductionEnv', '20180910_140105')
when:
URL url = new URL("http://demoaut.katalon.com/")
int startingDepth = 0
String defaultName = "top"
String result = mri.resolveFileNameByURLPathComponents(
url, startingDepth, defaultName)
then:
assert "top.png" == result
}

}

0 comments on commit cd09d0b

Please sign in to comment.