<commit_before>import execa from 'execa'
import fs from 'fs-extra'
import { forEach } from 'lodash'

import LocalHandler from './local'

const DEFAULT_NFS_OPTIONS = 'vers=3'

export default class NfsHandler extends LocalHandler {
  get type () {
    return 'nfs'
  }

  _getRealPath () {
    return `/run/xo-server/mounts/${this._remote.id}`
  }

  async _loadRealMounts () {
    let stdout
    const mounted = {}
    try {
      stdout = await execa.stdout('findmnt', [
        '-P',
        '-t',
        'nfs,nfs4',
        '--output',
        'SOURCE,TARGET',
        '--noheadings',
      ])
      const regex = /^SOURCE="([^:]*):(.*)" TARGET="(.*)"$/
      forEach(stdout.split('\n'), m => {
        if (m) {
          const match = regex.exec(m)
          mounted[match[3]] = {
            host: match[1],
            share: match[2],
          }
        }
      })
    } catch (exc) {
      // When no mounts are found, the call pretends to fail...
      if (exc.stderr !== '') {
        throw exc
      }
    }

    this._realMounts = mounted
    return mounted
  }

  _matchesRealMount () {
    return this._getRealPath() in this._realMounts
  }

  async _mount () {
    await fs.ensureDir(this._getRealPath())
    const { host, path, port, options } = this._remote
    return execa('mount', [
      '-t',
      'nfs',
      '-o',
      DEFAULT_NFS_OPTIONS + (options !== undefined ? `,${options}` : ''),
      `${host}${port !== undefined ? ':' + port : ''}:${path}`,
      this._getRealPath(),
    ])
  }

  async _sync () {
    await this._loadRealMounts()
    if (this._matchesRealMount() && !this._remote.enabled) {
      await this._umount(this._remote)
    } else if (!this._matchesRealMount() && this._remote.enabled) {
      await this._mount()
    }
    return this._remote
  }

  async _forget () {
    try {
      await this._umount(this._remote)
    } catch (_) {
      // We have to go on...
    }
  }

  async _umount (remote) {
    await execa('umount', ['--force', this._getRealPath()])
  }
}<commit_msg>chore(fs/NfsHandler#_umount): remove unused remote param<commit_after>import execa from 'execa'
import fs from 'fs-extra'
import { forEach } from 'lodash'

import LocalHandler from './local'

const DEFAULT_NFS_OPTIONS = 'vers=3'

export default class NfsHandler extends LocalHandler {
  get type () {
    return 'nfs'
  }

  _getRealPath () {
    return `/run/xo-server/mounts/${this._remote.id}`
  }

  async _loadRealMounts () {
    let stdout
    const mounted = {}
    try {
      stdout = await execa.stdout('findmnt', [
        '-P',
        '-t',
        'nfs,nfs4',
        '--output',
        'SOURCE,TARGET',
        '--noheadings',
      ])
      const regex = /^SOURCE="([^:]*):(.*)" TARGET="(.*)"$/
      forEach(stdout.split('\n'), m => {
        if (m) {
          const match = regex.exec(m)
          mounted[match[3]] = {
            host: match[1],
            share: match[2],
          }
        }
      })
    } catch (exc) {
      // When no mounts are found, the call pretends to fail...
      if (exc.stderr !== '') {
        throw exc
      }
    }

    this._realMounts = mounted
    return mounted
  }

  _matchesRealMount () {
    return this._getRealPath() in this._realMounts
  }

  async _mount () {
    await fs.ensureDir(this._getRealPath())
    const { host, path, port, options } = this._remote
    return execa('mount', [
      '-t',
      'nfs',
      '-o',
      DEFAULT_NFS_OPTIONS + (options !== undefined ? `,${options}` : ''),
      `${host}${port !== undefined ? ':' + port : ''}:${path}`,
      this._getRealPath(),
    ])
  }

  async _sync () {
    await this._loadRealMounts()
    if (this._matchesRealMount() && !this._remote.enabled) {
      await this._umount()
    } else if (!this._matchesRealMount() && this._remote.enabled) {
      await this._mount()
    }
    return this._remote
  }

  async _forget () {
    try {
      await this._umount(this._remote)
    } catch (_) {
      // We have to go on...
    }
  }

  async _umount () {
    await execa('umount', ['--force', this._getRealPath()])
  }
}
{'fraction_non_alphanumeric': 0.16638120871054562, 'fraction_numerical': 0.002446782481037436, 'mean_word_length': 2.1040242976461654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2200667', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1371, 'n_words': 299}