Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace myDeleteRecursively with deleteRecursively #10

Merged
merged 1 commit into from
Apr 12, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.saveourtool.processbuilder.exceptions.ProcessExecutionException
import com.saveourtool.processbuilder.exceptions.ProcessTimeoutException
import com.saveourtool.processbuilder.utils.createFile
import com.saveourtool.processbuilder.utils.isCurrentOsWindows
import com.saveourtool.processbuilder.utils.myDeleteRecursively
import com.saveourtool.processbuilder.utils.readLines
import io.github.oshai.KotlinLogging
import okio.FileSystem
Expand Down Expand Up @@ -92,7 +91,7 @@ class ProcessBuilder(private val useInternalRedirections: Boolean, private val f
val stdout = fs.readLines(stdoutFile)
val stderr = fs.readLines(stderrFile)

fs.myDeleteRecursively(tmpDir)
fs.deleteRecursively(tmpDir)
logger.trace { "Removed temp directory $tmpDir" }
if (stderr.isNotEmpty()) {
logger.debug { "stderr of `$command`:\t${stderr.joinToString("\t")}" }
Expand Down Expand Up @@ -158,6 +157,7 @@ class ProcessBuilder(private val useInternalRedirections: Boolean, private val f
}
// Command already contains correct signature.
// We also believe not to met complex cases: `echo a; echo | set /p="a && echo b"`
// TODO: https://github.com/saveourtool/process-builder-multiplatform/issues/5
val cmdWithoutWhitespaces = command.replace(" ", "")
if (cmdWithoutWhitespaces.contains("echo|set")) {
return command
Expand All @@ -177,6 +177,7 @@ class ProcessBuilder(private val useInternalRedirections: Boolean, private val f
val listOfCommands = if (separator != "") command.split(separator) as MutableList<String> else mutableListOf(command)
listOfCommands.forEachIndexed { index, cmd ->
if (cmd.contains("echo")) {
// TODO: https://github.com/saveourtool/process-builder-multiplatform/issues/5
var newEchoCommand = cmd.trim(' ').replace("echo ", " echo | set /p dummyName=\"")
// Now we need to add closing `"` in proper place
// Despite the fact, that we don't expect user redirections, for out internal tests we use them,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@

package com.saveourtool.processbuilder.utils

import io.github.oshai.KotlinLogging
import okio.FileSystem
import okio.Path
import kotlin.jvm.JvmName

expect val fs: FileSystem

internal val fileUtilsLogger = KotlinLogging.logger { }

/**
* Delete this directory and all other files and directories in it
*
* @param path a path to a directory
*/
expect fun FileSystem.myDeleteRecursively(path: Path)

/**
* Create file in [this] [FileSystem], denoted by [Path] [path]
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,5 @@
package com.saveourtool.processbuilder.utils

import okio.FileSystem
import okio.Path
import java.nio.file.Files

actual val fs: FileSystem = FileSystem.SYSTEM

actual fun FileSystem.myDeleteRecursively(path: Path) {
path.toFile().walkBottomUp().forEach { file ->
fileUtilsLogger.trace { "Attempt to delete file $file" }
Files.delete(file.toPath())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,5 @@
package com.saveourtool.processbuilder.utils

import okio.FileSystem
import okio.Path
import platform.posix.FTW_DEPTH
import platform.posix.nftw
import platform.posix.remove

import kotlinx.cinterop.staticCFunction
import kotlinx.cinterop.toKString

actual val fs: FileSystem = FileSystem.SYSTEM

@Suppress("MAGIC_NUMBER", "MagicNumber")
actual fun FileSystem.myDeleteRecursively(path: Path) {
nftw(path.toString(), staticCFunction { pathName, _, _, _ ->
val fileName = pathName!!.toKString()
fileUtilsLogger.trace { "Attempt to delete file $fileName" }
remove(fileName)
}, 64, FTW_DEPTH)
}