Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions api/src/org/labkey/api/pipeline/PipelineJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,17 @@ public Path getRemoteLogPath()
/** Finds a file name that hasn't been used yet, appending ".2", ".3", etc as needed */
public static File findUniqueLogFile(File primaryFile, String baseName)
{
String validBaseName = FileUtil.makeLegalName(baseName);
// need to look in current and archived dirs for any unused log file names (issue 20987)
File fileLog = FT_LOG.newFile(primaryFile.getParentFile(), baseName);
File fileLog = FT_LOG.newFile(primaryFile.getParentFile(), validBaseName);
File archivedDir = new File(primaryFile.getParentFile(), AssayFileWriter.ARCHIVED_DIR_NAME);
File fileLogArchived = FT_LOG.newFile(archivedDir, baseName);
File fileLogArchived = FT_LOG.newFile(archivedDir, validBaseName);

int index = 1;
while (NetworkDrive.exists(fileLog) || NetworkDrive.exists(fileLogArchived))
{
fileLog = FT_LOG.newFile(primaryFile.getParentFile(), baseName + "." + (index));
fileLogArchived = FT_LOG.newFile(archivedDir, baseName + "." + (index++));
fileLog = FT_LOG.newFile(primaryFile.getParentFile(), validBaseName + "." + (index));
fileLogArchived = FT_LOG.newFile(archivedDir, validBaseName + "." + (index++));
}

return fileLog;
Expand Down
8 changes: 5 additions & 3 deletions api/src/org/labkey/api/util/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ public FileType(List<String> suffixes, String defaultSuffix, boolean dir, gzSupp
private String tryName(Path parentDir, String name)
{
if (_supportGZ.booleanValue()) // TPP treats xml.gz as a native format
{ // in the case of existing files, non-gz copy wins if present
{
FileUtil.legalPathPartThrow(name);
// in the case of existing files, non-gz copy wins if present
Path f = parentDir!=null ? FileUtil.appendName(parentDir, name) : Path.of(name);
if (!NetworkDrive.exists(f))
{ // non-gz copy doesn't exist - how about .gz version?
Expand Down Expand Up @@ -340,7 +342,7 @@ public String getName(Path parentDir, String basename)
for (String suffix : _suffixes)
{
String name = tryName(parentDir, basename + suffix);
Path f = parentDir.resolve(name);
Path f = FileUtil.appendName(parentDir, name);
if (NetworkDrive.exists(f))
{
// avoid, for example, mistaking protxml ".pep-prot.xml" for pepxml ".xml" file
Expand Down Expand Up @@ -372,7 +374,7 @@ public File getFile(File parentDir, String basename)

public Path getPath(Path parentDir, String basename)
{
return parentDir.resolve(getName(parentDir, basename));
return FileUtil.appendName(parentDir, getName(parentDir, basename));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public static Path appendName(Path dir, String name)

// narrower check than isLegalName() or isAllowedFileName()
// this check that a name is a valid path part (e.g. filename) and is not path like.
private static void legalPathPartThrow(String name)
public static void legalPathPartThrow(String name)
{
int invalidCharacterIndex = StringUtils.indexOfAny(name, '/', File.separatorChar);
if (invalidCharacterIndex >= 0)
Expand Down