docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

cp commands in i18n tutorial create duplicate file (recursing AND globbing)

Open smallsaucepan opened this issue 6 months ago • 2 comments

Have you read the Contributing Guidelines on issues?

Description

Running through the i18n tutorial the cp commands under "Translate Markdown Files" were giving unexpected results.

cp -r docs/** i18n/fr/docusaurus-plugin-content-docs/current

In some shells, mine included, this leads to duplicate files because the shell globs all the files in all the subdirectories first and then recursively copies each one individually to the destination. So I end up with

api/file1.md
type/file2.md
file1.md
file2.md

Suspect globbing is used at all because in a later command we only want to include md and mdx files, so straight recursion would be too blunt an instrument:

cp -r src/pages/**.md i18n/fr/docusaurus-plugin-content-pages

Realise these commands are probably meant to be as simple as possible, though they could cause confusion for someone who doesn't twig to -r and ** doing similar things. Would like to hear any thoughts before suggesting a PR to fix. Would it be better to:

  1. change the commands to only use recursion OR globbing if possible
  2. use other utilities like find or cpio which may look more daunting but work more predictably
  3. add a warning message and link to more info "if you see duplicate files in the destination directory"

Self-service

  • [x] I'd be willing to address this documentation request myself.

smallsaucepan avatar May 07 '25 22:05 smallsaucepan

In some shells, mine included

Which shell are you using?


I'm open to suggestions to improve things, but it looks like difficult to craft a simple command that permits to reliably copy files for all possible systems/shells

We already had a similar problem in the past: https://github.com/facebook/docusaurus/pull/8704

Ultimately, it's impossible for us to provide a command than can be run anywhere (including future OS/shells that do not exist yet). The best option is probably to add a warning mentioning that the user should adjust the command to their OS/shell

slorber avatar May 15 '25 11:05 slorber

Fish. Please dont ask why - I've forgotten 😅

How about the below right after the first command:

:::warning

If you notice duplicate files in the destination directory after running the commands in this section, your shell may be configured to enable globstar functionality. Consult the documentation for your shell to tailor equivalent commands for your environment.

smallsaucepan avatar May 17 '25 11:05 smallsaucepan