Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-25839

shell mkdir should return whether a new directory was created

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0-rc0
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Minor Change
    • Platforms 2016-09-19, Platforms 2016-10-10

      The shell's mkdir() function is a wrapper around boost::filesystem::create_directories(). This function returns a bool indicating whether or not a new directory was created. However, the shell's mkdir throws away this return status, and instead always returns true (which is useless).

      This makes it impossible for shell code to determine whether a new directory has been created or not. This would be helpful for jstest code that needs to atomically create a new directory of its own, so that it can work inside that directory without worrying about other concurrent runs of the jstest, etc.

      The new return status should satisfy:

      • Truthy on success, so that existing code which (erroneously) checks the result of mkdir() still works.
      • User understandability. Currently users see
        > mkdir("foo")
        true
        

        which will be presumed to mean "okay, that has been done". The return value should be similarly understandable "at first glance".

      Simply returning the bool from boost::filesystem::create_directories() fails both of these requirements. Better would be to return an object such as

      > mkdir("foo")
      { exists: true, created: true }
      > mkdir("foo")
      { exists: true, created: false }
      

      where the exists field is always true, indicating that the directory now exists (because if there was an error, an assertion would have been thrown), and the created field contains the result from create_directories (ie. whether or not a directory was actually created in response to this mkdir(), or whether the directory was pre-existing).

            Assignee:
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: