Files
2025-10-25 03:02:53 +03:00

6.0 KiB
Raw Permalink Blame History

[fs.op.copy]

31 Input/output library [input.output]

31.12 File systems [filesystems]

31.12.13 Filesystem operation functions [fs.op.funcs]

31.12.13.4 Copy [fs.op.copy]

🔗

void filesystem::copy(const path& from, const path& to);

1

#

Effects: Equivalent tocopy(from, to, copy_options::none).

🔗

void filesystem::copy(const path& from, const path& to, error_code& ec);

2

#

Effects: Equivalent tocopy(from, to, copy_options::none, ec).

🔗

void filesystem::copy(const path& from, const path& to, copy_options options); void filesystem::copy(const path& from, const path& to, copy_options options, error_code& ec);

3

#

Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set in options.

4

#

Effects: Before the first use of f and t:

If(options & copy_options::create_symlinks) != copy_options::none ||(options & copy_options::skip_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = symlink_status(to).

Otherwise, if(options & copy_options::copy_symlinks) != copy_options::none then auto f = symlink_status(from) and if needed auto t = status(to).

Otherwise, auto f = status(from) and if needed auto t = status(to).

Effects are then as follows:

exists(f) is false, or

equivalent(from, to) is true, or

is_other(f) || is_other(t) is true, or

is_directory(f) && is_regular_file(t) is true.

  • (4.6)

    Otherwise, if is_symlink(f), then:

    • (4.6.1)

      If(options & copy_options::skip_symlinks) != copy_options::none then return.

    • (4.6.2)

      Otherwise if!exists(t) && (options & copy_options::copy_symlinks) != copy_options::none then copy_symlink(from, to).

    • (4.6.3)

      Otherwise report an error as specified in [fs.err.report].

  • (4.7)

    Otherwise, if is_regular_file(f), then:

    • (4.7.1)

      If (options & copy_options::directories_only) != copy_options::none, then return.

    • (4.7.2)

      Otherwise, if (options & copy_options::create_symlinks) != copy_options::none, then create a symbolic link to the source file.

    • (4.7.3)

      Otherwise, if (options & copy_options::create_hard_links) != copy_options::none, then create a hard link to the source file.

    • (4.7.4)

      Otherwise, if is_directory(t), then copy_file(from, to/from.filename(), options).

    • (4.7.5)

      Otherwise, copy_file(from, to, options).

  • (4.8)

    Otherwise, ifis_directory(f) &&(options & copy_options::create_symlinks) != copy_options::none then report an error with an error_code argument equal to make_error_code(errc::is_a_directory).

  • (4.9)

    Otherwise, ifis_directory(f) &&((options & copy_options::recursive) != copy_options::none || options == copy_options::none) then:

If exists(t) is false, then create_directory(to, from).

Then, iterate over the files in from, as if byfor (const directory_entry& x : directory_iterator(from)) copy(x.path(), to/x.path().filename(), options | copy_options::in-recursive-copy); where in-recursive-copy is a bitmask element of copy_options that is not one of the elements in [fs.enum.copy.opts].

  • (4.10)

    Otherwise, for the signature with argument ec, ec.clear().

  • (4.11)

    Otherwise, no effects.

5

#

Throws: As specified in [fs.err.report].

6

#

Remarks: For the signature with argument ec, any library functions called by the implementation shall have an error_code argument if applicable.

7

#

[Example 1:

Given this directory structure:

/dir1
  file1
  file2
  dir2
    file3

Calling copy("/dir1", "/dir3") would result in:

/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2

Alternatively, calling copy("/dir1", "/dir3", copy_options::recursive) would result in:

/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2
  dir2
    file3

— end example]