Copy files, directories and symlinks


\begin{DoxyCode}{0}
\DoxyCodeLine{const copy = require('copy-\/concurrently')}
\DoxyCodeLine{copy('/path/to/thing', '/new/path/thing').then(() => \{}
\DoxyCodeLine{  // this is now copied}
\DoxyCodeLine{\}).catch(err => \{}
\DoxyCodeLine{  // oh noooo}
\DoxyCodeLine{\}) }

\end{DoxyCode}


Copies files, directories and symlinks. Ownership is maintained when running as root, permissions are always maintained. On Windows, if symlinks are unavailable then junctions will be used.\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6598}{}\doxysection{PUBLIC INTERFACE}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6598}
\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6599}{}\doxysubsection{copy(from, to, \mbox{[}options\mbox{]}) → Promise}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6599}
Recursively copies {\ttfamily from} to {\ttfamily to} and resolves its promise when finished. If {\ttfamily to} already exists then the promise will be rejected with an {\ttfamily EEXIST} error.

Options are\+:


\begin{DoxyItemize}
\item max\+Concurrency – (Default\+: {\ttfamily 1}) The maximum number of concurrent copies to do at once.
\item recurse\+With -\/ (Default\+: {\ttfamily copy.\+item}) The function to call on each file after recursing into a directory.
\item is\+Windows -\/ (Default\+: `process.\+platform === \textquotesingle{}win32'{\ttfamily ) If true enables Windows symlink semantics. This requires an extra}stat\`{} to determine if the destination of a symlink is a file or directory. If symlinking a directory fails then we\textquotesingle{}ll try making a junction instead.
\end{DoxyItemize}

Options can also include dependency injection\+:


\begin{DoxyItemize}
\item Promise -\/ (Default\+: {\ttfamily global.\+Promise}) The promise implementation to use, defaults to Node\textquotesingle{}s.
\item fs -\/ (Default\+: `require(\textquotesingle{}fs'){\ttfamily ) The filesystem module to use. Can be used to use}graceful-\/fs{\ttfamily or to inject a mock.}
\item {\ttfamily write\+Stream\+Atomic -\/ (Default\+:}require(\textquotesingle{}fs-\/write-\/stream-\/atomic\textquotesingle{}){\ttfamily ) The implementation of}write\+Stream\+Atomic{\ttfamily to use. Used to inject a mock.}
\item {\ttfamily getuid -\/ (Default\+:}process.\+getuid\`{}) A function that returns the current UID. Used to inject a mock.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6600}{}\doxysection{EXTENSION INTERFACE}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6600}
Ordinarily you\textquotesingle{}d only call {\ttfamily copy} above. But it\textquotesingle{}s possible to use it\textquotesingle{}s component functions directly. This is useful if, say, you\textquotesingle{}re writing \href{https://npmjs.com/package/move-concurrently}{\texttt{ move-\/concurently}}.\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6601}{}\doxysubsection{copy.\+file(from, to, options) → Promise}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6601}
Copies an ordinary file {\ttfamily from} to destination {\ttfamily to}. Uses {\ttfamily fs-\/write-\/stream-\/atomic} to ensure that the file is either entirely copied or not at all.

Options are\+:


\begin{DoxyItemize}
\item uid, gid -\/ (Optional) If {\ttfamily getuid()} is {\ttfamily 0} then this and gid will be used to set the user and group of {\ttfamily to}. If uid is present then gid must be too.
\item mode -\/ (Optional) If set then {\ttfamily to} will have its perms set to {\ttfamily mode}.
\item fs -\/ (Default\+: `require(\textquotesingle{}fs'){\ttfamily ) The filesystem module to use. Can be used to use}graceful-\/fs{\ttfamily or to inject a mock.}
\item {\ttfamily Promise -\/ (Default\+:}global.\+Promise$<$tt$>$) The promise implementation to use, defaults to Node\textquotesingle{}s.
\item write\+Stream\+Atomic -\/ (Defaultrequire(\textquotesingle{}fs-\/write-\/stream-\/atomic\textquotesingle{}){\ttfamily ) The implementation of}write\+Stream\+Atomic\`{} to use. Used to inject a mock.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6602}{}\doxysubsection{copy.\+symlink(from, to, options) → Promise}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6602}
Copies a symlink {\ttfamily from} to destination {\ttfamily to}. If you\textquotesingle{}re using Windows and symlinking fails and what you\textquotesingle{}re linking is a directory then junctions will be tried instead.

Options are\+:


\begin{DoxyItemize}
\item top -\/ The top level the copy is being run from. This is used to determine if the symlink destination is within the set of files we\textquotesingle{}re copying or outside it.
\item fs -\/ (Default\+: `require(\textquotesingle{}fs'){\ttfamily ) The filesystem module to use. Can be used to use}graceful-\/fs{\ttfamily or to inject a mock.}
\item {\ttfamily Promise -\/ (Default\+:}global.\+Promise$<$tt$>$) The promise implementation to use, defaults to Node\textquotesingle{}s.
\item is\+Windows -\/ (Default\+:process.\+platform === \textquotesingle{}win32\textquotesingle{}{\ttfamily ) If true enables Windows symlink semantics. This requires an extra}stat\`{} to determine if the destination of a symlink is a file or directory. If symlinking a directory fails then we\textquotesingle{}ll try making a junction instead.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6603}{}\doxysubsection{copy.\+recurse(from, to, options) → Promise}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6603}
Reads all of the files in directory {\ttfamily from} and adds them to the {\ttfamily queue} using {\ttfamily recurse\+With} (by default {\ttfamily copy.\+item}).

Options are\+:


\begin{DoxyItemize}
\item queue -\/ A \href{https://npmjs.com/package/run-queue}{\texttt{ {\ttfamily run-\/queue}}} object to add files found inside {\ttfamily from} to.
\item recurse\+With -\/ (Default\+: {\ttfamily copy.\+item}) The function to call on each file after recursing into a directory.
\item uid, gid -\/ (Optional) If {\ttfamily getuid()} is {\ttfamily 0} then this and gid will be used to set the user and group of {\ttfamily to}. If uid is present then gid must be too.
\item mode -\/ (Optional) If set then {\ttfamily to} will have its perms set to {\ttfamily mode}.
\item fs -\/ (Default\+: `require(\textquotesingle{}fs'){\ttfamily ) The filesystem module to use. Can be used to use}graceful-\/fs{\ttfamily or to inject a mock.}
\item {\ttfamily getuid -\/ (Default\+:}process.\+getuid\`{}) A function that returns the current UID. Used to inject a mock.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6604}{}\doxysubsection{copy.\+item(from, to, options) → Promise}\label{md_sfcode_node_modules_copy_concurrently_README_autotoc_md6604}
Copies some kind of {\ttfamily from} to destination {\ttfamily to}. This looks at the filetype and calls {\ttfamily copy.\+file}, {\ttfamily copy.\+symlink} or {\ttfamily copy.\+recurse} as appropriate.

Symlink copies are queued with a priority such that they happen after all file and directory copies as you can\textquotesingle{}t create a junction on windows to a file that doesn\textquotesingle{}t exist yet.

Options are\+:


\begin{DoxyItemize}
\item top -\/ The top level the copy is being run from. This is used to determine if the symlink destination is within the set of files we\textquotesingle{}re copying or outside it.
\item queue -\/ The \href{https://npmjs.com/package/run-queue}{\texttt{ {\ttfamily run-\/queue}}} object to pass to {\ttfamily copy.\+recurse} if {\ttfamily from} is a directory.
\item recurse\+With -\/ (Default\+: {\ttfamily copy.\+item}) The function to call on each file after recursing into a directory.
\item uid, gid -\/ (Optional) If {\ttfamily getuid()} is {\ttfamily 0} then this and gid will be used to set the user and group of {\ttfamily to}. If uid is present then gid must be too.
\item mode -\/ (Optional) If set then {\ttfamily to} will have its perms set to {\ttfamily mode}.
\item fs -\/ (Default\+: `require(\textquotesingle{}fs'){\ttfamily ) The filesystem module to use. Can be used to use}graceful-\/fs{\ttfamily or to inject a mock.}
\item {\ttfamily getuid -\/ (Default\+:}process.\+getuid$<$tt$>$) A function that returns the current UID. Used to inject a mock.
\item is\+Windows -\/ (Default\+:process.\+platform === \textquotesingle{}win32\textquotesingle{}{\ttfamily ) If true enables Windows symlink semantics. This requires an extra}stat\`{} to determine if the destination of a symlink is a file or directory. If symlinking a directory fails then we\textquotesingle{}ll try making a junction instead.
\item Promise -\/ (Default\+: {\ttfamily global.\+Promise}) The promise implementation to use, defaults to Node\textquotesingle{}s.
\item write\+Stream\+Atomic -\/ (Default `require(\textquotesingle{}fs-\/write-\/stream-\/atomic'){\ttfamily ) The implementation of}write\+Stream\+Atomic\`{} to use. Used to inject a mock. 
\end{DoxyItemize}