[SERVER-71876] writeFile() shell helper errors when given relative path Created: 05/Dec/22  Updated: 29/Oct/23  Resolved: 08/Dec/22

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

Type: Bug Priority: Major - P3
Reporter: Zixuan Zhuang Assignee: Alex Neben
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
Problem/Incident
is caused by SERVER-60440 Update boost to latest stable version Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

https://parsley.mongodb.com/resmoke/1f6e1b36c547528b43d40fb62a7cb702/test/172d251d2c74a35cc5e2fa94ef12aafa?bookmarks=0,7873,8044&selectedLine=0

[js_test:query_fuzzer-3cbd-1670031823821-0] Error: writeFile() can only write a file in a directory which already exists :
[js_test:query_fuzzer-3cbd-1670031823821-0] writeOutput@jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js:1641:11
[js_test:query_fuzzer-3cbd-1670031823821-0] minimizeOutput@jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js:3731:16
[js_test:query_fuzzer-3cbd-1670031823821-0] main@jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js:3792:23
[js_test:query_fuzzer-3cbd-1670031823821-0] @jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js:3805:1
[js_test:query_fuzzer-3cbd-1670031823821-0] @jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js:3807:2
[js_test:query_fuzzer-3cbd-1670031823821-0] failed to load: jstestfuzz/out/query_fuzzer-3cbd-1670031823821-0.js
[js_test:query_fuzzer-3cbd-1670031823821-0] exiting with code -3 

The writeOutput function is

export function writeOutput(minimizerOutputs: MinimizedOutputs) {
    try {
        shell.removeFile('./minimizer-outputs.json');
    } catch (_) {
        // pass
    }
    shell.writeFile(
        './minimizer-outputs.json',
        JSON.stringify(formatMinimizedOutputs(minimizerOutputs))
    );
} 



 Comments   
Comment by Githook User [ 08/Dec/22 ]

Author:

{'name': 'Alexander Neben', 'email': 'alexander.neben@mongodb.com', 'username': 'IamXander'}

Message: SERVER-71876 writeFile now works when passing a relative path
Branch: master
https://github.com/mongodb/mongo/commit/c19c6084fd2ce1cec263e16bb48c4dbf9fa74187

Comment by Alex Neben [ 07/Dec/22 ]

Between both versions boost `("./abc.txt").lexically_normal()` returned `./abc.txt` and now returns `abc.txt`. Feeding the following into `boost::parent_path` the former worked as expected and the latter caused an error.

Comment by Alex Neben [ 07/Dec/22 ]

Just confirmed the boost upgrade caused the problem.
https://github.com/mongodb/mongo/commit/13389dc222fc372442be8c147e09685bb9a26a3a

(mongo-venv) ➜  mongo3 git:(0cc2ede603f) ✗ ./build/install/bin/mongo --nodb
MongoDB shell version v6.1.0-alpha
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
    https://community.mongodb.com
> version()
6.1.0-alpha
> version()
6.1.0-alpha
> writeFile("./output.txt", "test")
> ^C
bye 

vs

(mongo-venv) ➜  mongo2 git:(13389dc222f) ✗ ./build/install/bin/mongo --nodb
MongoDB shell version v6.1.0-alpha
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
> version()
6.1.0-alpha
> writeFile("./output.txt", "test")
Error: writeFile() can only write a file in a directory which already exists :
@(shell):1:10 

This upgrade was from boost 1.76 -> 1.79. Looking through the docs to find how to restore previous behavior.

Comment by Max Hirschhorn [ 07/Dec/22 ]

I'm concerned we don't have an understanding as to why the behavior of writeFile() changed across MongoDB versions despite its C++ definition not having been changed.

> version()
6.3.0-alpha-84-g450ed08
> writeFile("./output.txt", "test")
Error: writeFile() can only write a file in a directory which already exists :
@(shell):1:10

> version()
4.4.15-13-gead0d92
> writeFile("./output.txt", "test")
> cat("./output.txt")
test

Comment by Alex Neben [ 07/Dec/22 ]

To me it seems like the workaround works fine (e.g. prepending pwd() + path). Please feel free to reopen if you are concerned about this approach.

Comment by Zixuan Zhuang [ 06/Dec/22 ]

The patch build: https://spruce.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_80_64_bit_dynamic_classic_engine_query_patch_only_query_fuzzer_plan_cache_1_linux_enterprise_patch_ee8a38cc92b5ff1e39ff2e702a17e25d29280409_6386a4b7a4cf477d15f5d2f9_22_11_30_00_33_46/tests?execution=3&sortBy=STATUS&sortDir=ASC

 

Generated at Thu Feb 08 06:20:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.