adamreisnz/replace-in-file

Replace in files on network drive?

jschuman opened this issue · 8 comments

I'm having some trouble getting this to work on files on a network drive.

For example, I set my files attribute to something like this:
let files = "\\\\share_name\\Users\\Public\\jschuman\\*.html"

but no file replacements occur (and I know there should be).

Is this possible?

@jschuman thanks for reporting, I think your issue may be similar to #32

Could you try using the disableGlobs: true flag and see if that helps?

ok, that does work but I am (not surprisingly) unable to then use my *.html wildcard as in my example above. The parent folder has thousands of files I am looking through for replacement so guessing I am just out-of-luck for now?

Yes I see what you mean. Unfortunately I am unable to test this myself as I don't have access to any windows machines or network drives.

Would you be able to look into this and dig deeper to see if you can find a solution?

Maybe this thread can help: isaacs/node-glob#74

Perhaps it's sufficient if we allow you to pass in the cwd parameter to the glob options?

As a followup, I did get this working as a POC locally (at least for the sync version). It was fairly straightforward and, yes, @adamreisnz it was really just a question of supporting the cwd parameter. Unfortunately, with our use case the performance was intolerable when applying to the network drive vs. copying and performing locally so it's really infeasible for our use case.

Here's a summation of what I found in case I have time to create a PR later or someone else has the time. Again, this was just a POC to get working with the sync function, so a more thorough solution is definitely needed:

  • updated replaceInFile.sync to support the cwd option
  • updated getPathsSync to add cwd option to the config; but only if present
  • updated getPathsSync to also preface each path returned by glob.sync with the cwd (if present) before returning paths

That was what was needed to support the cwd parameter, and then my use of replace-in-file had to be adjusted in the following way:

  • when using UNC, I set the cwd parameter to the UNC path (i.e., \\\\share_name\\Users\\Public\\jschuman\\)
  • the files parameter was then set with the wildcard (e.g. to **/*.html for my use case)

I hope this helps.

Thanks @jschuman, if I have time myself I'll look at implementing support for the cwd flag.

@jschuman I have added support for the cwd parameter in 4.0.0, would you mind taking it for a spin and see if it resolves the issue you had?

@jschuman I'll close this issue now, but if you have a minute and can check if the new version works for you that'd be great.