diff --git a/internal/callgraph/language/java11/job.go b/internal/callgraph/language/java11/job.go index 1ab7d981..5b749ecb 100644 --- a/internal/callgraph/language/java11/job.go +++ b/internal/callgraph/language/java11/job.go @@ -99,9 +99,11 @@ func (j *Job) runCallGraph(callgraph ICallgraph) { } func (j *Job) runPostProcess() { - outputNameZip := outputName + ".zip" + workingDirectory := j.GetDir() + outputFullPath := path.Join(workingDirectory, outputName) + outputFullPathZip := outputFullPath + ".zip" j.SendStatus("zipping callgraph") - err := j.archive.ZipFile(outputName, outputNameZip) + err := j.archive.ZipFile(outputFullPath, outputFullPathZip) if err != nil { j.Errors().Critical(err) @@ -109,7 +111,7 @@ func (j *Job) runPostProcess() { } j.SendStatus("base64 encoding zipped callgraph") - err = j.archive.B64(outputNameZip, outputName) + err = j.archive.B64(outputFullPathZip, outputFullPath) if err != nil { j.Errors().Critical(err) @@ -117,7 +119,7 @@ func (j *Job) runPostProcess() { } j.SendStatus("cleanup") - err = j.archive.Cleanup(outputNameZip) + err = j.archive.Cleanup(outputFullPathZip) if err != nil { e, ok := err.(*os.PathError) if ok && e.Err == syscall.ENOENT { diff --git a/internal/callgraph/language/java11/job_test.go b/internal/callgraph/language/java11/job_test.go index cdf98d7e..6d86da4f 100644 --- a/internal/callgraph/language/java11/job_test.go +++ b/internal/callgraph/language/java11/job_test.go @@ -121,7 +121,7 @@ func TestRunPostProcessMock(t *testing.T) { fs := ioTestData.FileSystemMock{} zip := ioTestData.ZipMock{} - archiveMock := io.NewArchiveWithStructs("dir", fs, zip) + archiveMock := io.NewArchiveWithStructs(dir, fs, zip) j := NewJob(dir, files, cmdFactoryMock, fileWriterMock, archiveMock, config, ctx) go jobTestdata.WaitStatus(j) @@ -190,3 +190,22 @@ func TestRunPostProcessCleanupNoFileExistError(t *testing.T) { assert.False(t, j.Errors().HasError()) } + +func TestRunPostProcessFromRoot(t *testing.T) { + fileWriterMock := &ioTestData.FileWriterMock{} + cmdFactoryMock := testdata.NewEchoCmdFactory() + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + ctx, _ := ctxTestdata.NewContextMock() + + err := &os.PathError{} + err.Err = syscall.ENOENT + archiveMock := ioTestData.ArchiveMock{PathError: err, Dir: "."} + + j := NewJob(dir, files, cmdFactoryMock, fileWriterMock, archiveMock, config, ctx) + go jobTestdata.WaitStatus(j) + j.runPostProcess() + + jobErrors := j.Errors().GetAll() + assert.True(t, jobErrors[0] == err) + +} diff --git a/internal/io/testdata/archive_mock.go b/internal/io/testdata/archive_mock.go index 001dac03..fe8517ec 100644 --- a/internal/io/testdata/archive_mock.go +++ b/internal/io/testdata/archive_mock.go @@ -1,12 +1,19 @@ package testdata +import "strings" + type ArchiveMock struct { ZipFileError error B64Error error CleanupError error + PathError error + Dir string } func (am ArchiveMock) ZipFile(sourceName string, targetName string) error { + if !strings.HasPrefix(sourceName, am.Dir) || !strings.HasPrefix(targetName, am.Dir) { + return am.PathError + } return am.ZipFileError }