jaulib v1.3.0
Jau Support Library (C++, Java, ..)
CopyOptions.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2022 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24package org.jau.fs;
25
26/**
27 * Filesystem copy options used to copy() path elements.
28 *
29 * By default, the fmode_t POSIX protection mode bits are preserved
30 * while using the caller's uid and gid as well as current timestamps. <br />
31 * Use {@link CopyOptions.Bit#preserve_all} to preserve uid and gid if allowed from the caller and access- and modification-timestamps.
32 *
33 * @see FileUtil#copy(String, String, CopyOptions)
34 */
35public class CopyOptions {
36 public enum Bit {
37 /** No option set */
38 none ( (short) 0 ),
39
40 /** Traverse through directories, i.e. perform visit, copy, remove etc actions recursively throughout the directory structure. */
41 recursive ( (short)( 1 << 0 ) ),
42
43 /** Copy referenced symbolic linked files or directories instead of just the symbolic link with property fmode_t::link set. */
44 follow_symlinks ( (short)( 1 << 1 ) ),
45
46 /**
47 * Copy source dir content into an already existing destination directory as if destination directory did not exist.
48 *
49 * Otherwise, if destination directory already exist, the source directory will be copied below the destination directory.
50 */
51 into_existing_dir ( (short)( 1 << 2 ) ),
52
53 /**
54 * Ignore errors from erroneous symlinks, e.g. non-existing link-targets, recursive loop-errors.or unsupported symmlinks on target filesystem.
55 *
56 * This flag is required to
57 * - copy erroneous non-existing symlinks if using follow_symlinks
58 * - copy erroneous recursive loop-error symlinks if using follow_symlinks
59 * - ignore symlinks if not supported by target filesystem if not using follow_symlinks
60 */
61 ignore_symlink_errors ( (short)( 1 << 8 ) ),
62
63 /** Overwrite existing destination files. */
64 overwrite ( (short)( 1 << 9 ) ),
65
66 /** Preserve uid and gid if allowed and access- and modification-timestamps, i.e. producing a most exact meta-data copy. */
67 preserve_all ( (short)( 1 << 10 ) ),
68
69 /** Ensure data and meta-data file synchronization is performed via ::fsync() after asynchronous copy operations of a file's content. */
70 sync ( (short)( 1 << 11 ) ),
71
72 /** Enable verbosity mode, show error messages on stderr. */
73 verbose ( (short)( 1 << 15 ) );
74
75 Bit(final short v) { value = v; }
76 public final short value;
77 }
78
79 public short mask;
80
81 public CopyOptions(final short v) {
82 mask = v;
83 }
84 public CopyOptions() {
85 mask = 0;
86 }
87
88 public boolean isSet(final Bit bit) { return bit.value == ( mask & bit.value ); }
89
90 /**
91 * Sets the given bit and returns this instance for chaining.
92 * @param bit the given Bit value to set
93 * @return this instance for chaining.
94 */
95 public CopyOptions set(final Bit bit) { mask = (short) ( mask | bit.value ); return this; }
96
97 @Override
98 public String toString() {
99 int count = 0;
100 final StringBuilder out = new StringBuilder();
101 for (final Bit dt : Bit.values()) {
102 if( isSet(dt) ) {
103 if( 0 < count ) { out.append(", "); }
104 out.append(dt.name()); count++;
105 }
106 }
107 if( 1 < count ) {
108 out.insert(0, "[");
109 out.append("]");
110 }
111 return out.toString();
112 }
113 @Override
114 public boolean equals(final Object other) {
115 if (this == other) {
116 return true;
117 }
118 return (other instanceof CopyOptions) &&
119 this.mask == ((CopyOptions)other).mask;
120 }
121}
Filesystem copy options used to copy() path elements.
CopyOptions(final short v)
boolean isSet(final Bit bit)
boolean equals(final Object other)
follow_symlinks
Copy referenced symbolic linked files or directories instead of just the symbolic link with property ...
sync
Ensure data and meta-data file synchronization is performed via ::fsync() after asynchronous copy ope...
recursive
Traverse through directories, i.e.
preserve_all
Preserve uid and gid if allowed and access- and modification-timestamps, i.e.
verbose
Enable verbosity mode, show error messages on stderr.
ignore_symlink_errors
Ignore errors from erroneous symlinks, e.g.
overwrite
Overwrite existing destination files.
into_existing_dir
Copy source dir content into an already existing destination directory as if destination directory di...