<commit_before>// #Sireum
/*
 Copyright (c) 2019, Robby, Kansas State University
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.sireum

object Os {

  @pure def cliArgs: ISZ[String] = {
    return Ext.cliArgs
  }

  @memoize def cwd: Path = {
    return Path.Impl(Ext.cwd)
  }

  def exit(code: Z): Unit = {
    Ext.exit(code)
  }

  def env(name: String): Option[String] = {
    return Ext.env(name)
  }

  def envs: Map[String, String] = {
    return Ext.envs
  }

  @pure def fileSep: String = {
    return Ext.fileSep
  }

  @memoize def home: Path = {
    return Path.Impl(Ext.home)
  }

  @pure def isLinux: B = {
    return kind == Kind.Linux
  }

  @pure def isMac: B = {
    return kind == Kind.Mac
  }

  @pure def isWin: B = {
    return kind == Kind.Win
  }

  @pure def pathSep: String = {
    return Ext.pathSep
  }

  @pure def kind: Kind.Type = {
    return Ext.os
  }

  @pure def path(value: String): Path = {
    if (isWin) {
      val sOps = ops.StringOps(value)
      val cygPrefix: String = "/cygdrive/"
      if (sOps.startsWith(cygPrefix)) {
        return Path.Impl(
          ops.StringOps(s"${sOps.substring(cygPrefix.size, cygPrefix.size + 1)}:${sOps.substring(cygPrefix.size + 1, value.size)}").replaceAllChars('/', '\\'))

      } else if (sOps.startsWith("/") && env("OSTYPE") == Some("msys")) {
        return Path.Impl(ops.StringOps(s"${sOps.substring(1, 2)}:${sOps.substring(2, value.size)}").
          replaceAllChars('/', '\\'))
      }
    }
    return Path.Impl(Ext.norm(value))
  }

  @pure def proc(commands: ISZ[String]): Proc = {
    return Proc(commands, cwd, Map.empty, T, None(), F, F, 0)
  }

  @memoize def roots: ISZ[Path] = {
    return for (root <- Ext.roots) yield Path.Impl(root)
  }

  def temp(): Path = {
    val r = tempFix("", "")
    return r
  }

  def tempFix(prefix: String, suffix: String): Path = {
    val r = Ext.temp(prefix, suffix)
    return Path.Impl(r)
  }

  def tempDir(): Path = {
    val r = tempDirFix("")
    return r
  }

  def tempDirFix(prefix: String): Path = {
    val r = Ext.tempDir(prefix)
    return Path.Impl(r)
  }


  @enum object Kind {
    'Mac
    'Linux
    'Win
    'Unsupported
  }

  object Path {

    @enum object Kind {
      'Dir
      'File
      'SymLink
      'Other
    }

    @enum object WriteMode {
      'Regular
      'Over
      'Append
    }

    @datatype class Impl(val value: String) extends Path {
      override def string: String = {
        return value
      }
    }

    @sig trait Jen[T] extends org.sireum.Jen[T] {
      def path: Path
      override def string: String = {
        return s"Jen($path)"
      }
    }

    @msig trait MJen[T] extends org.sireum.MJen[T] {
      def path: Path
      override def string: String = {
        return s"MJen($path)"
      }
    }

    def overlay(isMove: B, path: Os.Path, target: Os.Path, includeDir: B, followLink: B,
                pred: Os.Path => B @pure, report: B): HashSMap[Os.Path, Os.Path] = {
      var r = HashSMap.empty[Os.Path, Os.Path]
      val files = ops.ISZOps(walk(path, includeDir, T, pred)).reverse
      for (p <- files) {
        var rel = ISZ[String]()
        var t = p
        while (t.name != "dest" && t.up.name != "m2") {
          rel = t.name +: rel
          t = t.up
        }
        t = target / st"${(rel, Os.fileSep)}".render
        p.kind match {
          case Kind.Dir =>
            t.mkdirAll()
            if (isMove) {
              p.remove()
            }
            if (report) {
              r = r + p ~> t
            }
          case Kind.File =>
            t.up.mkdirAll()
            if (isMove) {
              p.moveOverTo(t)
            } else {<commit_msg>Fixed Os.Path.overlay.<commit_after>// #Sireum
/*
 Copyright (c) 2019, Robby, Kansas State University
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.sireum

object Os {

  @pure def cliArgs: ISZ[String] = {
    return Ext.cliArgs
  }

  @memoize def cwd: Path = {
    return Path.Impl(Ext.cwd)
  }

  def exit(code: Z): Unit = {
    Ext.exit(code)
  }

  def env(name: String): Option[String] = {
    return Ext.env(name)
  }

  def envs: Map[String, String] = {
    return Ext.envs
  }

  @pure def fileSep: String = {
    return Ext.fileSep
  }

  @memoize def home: Path = {
    return Path.Impl(Ext.home)
  }

  @pure def isLinux: B = {
    return kind == Kind.Linux
  }

  @pure def isMac: B = {
    return kind == Kind.Mac
  }

  @pure def isWin: B = {
    return kind == Kind.Win
  }

  @pure def pathSep: String = {
    return Ext.pathSep
  }

  @pure def kind: Kind.Type = {
    return Ext.os
  }

  @pure def path(value: String): Path = {
    if (isWin) {
      val sOps = ops.StringOps(value)
      val cygPrefix: String = "/cygdrive/"
      if (sOps.startsWith(cygPrefix)) {
        return Path.Impl(
          ops.StringOps(s"${sOps.substring(cygPrefix.size, cygPrefix.size + 1)}:${sOps.substring(cygPrefix.size + 1, value.size)}").replaceAllChars('/', '\\'))

      } else if (sOps.startsWith("/") && env("OSTYPE") == Some("msys")) {
        return Path.Impl(ops.StringOps(s"${sOps.substring(1, 2)}:${sOps.substring(2, value.size)}").
          replaceAllChars('/', '\\'))
      }
    }
    return Path.Impl(Ext.norm(value))
  }

  @pure def proc(commands: ISZ[String]): Proc = {
    return Proc(commands, cwd, Map.empty, T, None(), F, F, 0)
  }

  @memoize def roots: ISZ[Path] = {
    return for (root <- Ext.roots) yield Path.Impl(root)
  }

  def temp(): Path = {
    val r = tempFix("", "")
    return r
  }

  def tempFix(prefix: String, suffix: String): Path = {
    val r = Ext.temp(prefix, suffix)
    return Path.Impl(r)
  }

  def tempDir(): Path = {
    val r = tempDirFix("")
    return r
  }

  def tempDirFix(prefix: String): Path = {
    val r = Ext.tempDir(prefix)
    return Path.Impl(r)
  }


  @enum object Kind {
    'Mac
    'Linux
    'Win
    'Unsupported
  }

  object Path {

    @enum object Kind {
      'Dir
      'File
      'SymLink
      'Other
    }

    @enum object WriteMode {
      'Regular
      'Over
      'Append
    }

    @datatype class Impl(val value: String) extends Path {
      override def string: String = {
        return value
      }
    }

    @sig trait Jen[T] extends org.sireum.Jen[T] {
      def path: Path
      override def string: String = {
        return s"Jen($path)"
      }
    }

    @msig trait MJen[T] extends org.sireum.MJen[T] {
      def path: Path
      override def string: String = {
        return s"MJen($path)"
      }
    }

    def overlay(isMove: B, path: Os.Path, target: Os.Path, includeDir: B, followLink: B,
                pred: Os.Path => B @pure, report: B): HashSMap[Os.Path, Os.Path] = {
      var r = HashSMap.empty[Os.Path, Os.Path]
      val files = ops.ISZOps(walk(path, includeDir, T, pred)).reverse
      for (p <- files) {
        val t = target / path.relativize(p).string
        p.kind match {
          case Kind.Dir =>
            t.mkdirAll()
            if (isMove) {
              p.remove()
            }
            if (report) {
              r = r + p ~> t
            }
          case Kind.File =>
            t.up.mkdirAll()
            if (isMove) {
              p.moveOverTo(t)
            } else {
{'fraction_non_alphanumeric': 0.11529750875025736, 'fraction_numerical': 0.0025736051060325305, 'mean_word_length': 2.363919667590028, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1076662', 'n_tokens_mistral': 3257, 'n_tokens_neox': 3018, 'n_words': 999}