[SERVER-25839] shell mkdir should return whether a new directory was created Created: 29/Aug/16  Updated: 14/Mar/17  Resolved: 30/Sep/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 3.4.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Kevin Pulo Assignee: Samantha Ritter (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-9481 Docs for SERVER-25839: shell mkdir sh... Closed
Backwards Compatibility: Minor Change
Sprint: Platforms 2016-09-19, Platforms 2016-10-10
Participants:

 Description   

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).



 Comments   
Comment by Samantha Ritter (Inactive) [ 30/Sep/16 ]

mkdir now returns more complex output. It can still be evaluated as a boolean like before, but there are now two fields that can provide additional information to the user:

  • 'exists' holds 'true' if the directory exists after this call to mkdir
  • 'created' holds 'true' if the directory was created by this call to mkdir, 'false' if it already existed
Comment by Githook User [ 30/Sep/16 ]

Author:

{u'username': u'samantharitter', u'name': u'samantharitter', u'email': u'samantha.ritter@10gen.com'}

Message: SERVER-25839 Add a test for the shell's mkdir utility
Branch: master
https://github.com/mongodb/mongo/commit/8da6c8665fc06deac4f9258291dc93eabf3b3996

Comment by Githook User [ 30/Sep/16 ]

Author:

{u'username': u'samantharitter', u'name': u'samantharitter', u'email': u'samantha.ritter@10gen.com'}

Message: SERVER-25839 Improve shell 'mkdir' utility
Branch: master
https://github.com/mongodb/mongo/commit/d2d1b2bae272e786bcd6e79e4c5057672e971183

Generated at Thu Feb 08 04:10:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.