• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 26212181111

21 May 2026 07:33AM UTC coverage: 70.996% (+0.02%) from 70.979%
26212181111

Pull #1924

github

web-flow
Merge 1ee26558d into a61a0fa59
Pull Request #1924: #1884: keep symlinks while unzipping

4449 of 6932 branches covered (64.18%)

Branch coverage included in aggregate %.

11484 of 15510 relevant lines covered (74.04%)

3.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.68
cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
1
package com.devonfw.tools.ide.io;
2

3
import java.io.BufferedOutputStream;
4
import java.io.FileOutputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.OutputStream;
8
import java.io.Reader;
9
import java.io.Writer;
10
import java.net.http.HttpClient.Version;
11
import java.net.http.HttpResponse;
12
import java.nio.charset.StandardCharsets;
13
import java.nio.file.FileSystemException;
14
import java.nio.file.Files;
15
import java.nio.file.LinkOption;
16
import java.nio.file.NoSuchFileException;
17
import java.nio.file.Path;
18
import java.nio.file.StandardCopyOption;
19
import java.nio.file.attribute.BasicFileAttributes;
20
import java.nio.file.attribute.DosFileAttributeView;
21
import java.nio.file.attribute.FileTime;
22
import java.nio.file.attribute.PosixFileAttributeView;
23
import java.nio.file.attribute.PosixFilePermission;
24
import java.security.DigestInputStream;
25
import java.security.MessageDigest;
26
import java.security.NoSuchAlgorithmException;
27
import java.time.Duration;
28
import java.time.LocalDateTime;
29
import java.util.ArrayList;
30
import java.util.Enumeration;
31
import java.util.HashSet;
32
import java.util.Iterator;
33
import java.util.List;
34
import java.util.Objects;
35
import java.util.Properties;
36
import java.util.Set;
37
import java.util.function.Consumer;
38
import java.util.function.Function;
39
import java.util.function.Predicate;
40
import java.util.stream.Stream;
41

42
import org.apache.commons.compress.archivers.ArchiveEntry;
43
import org.apache.commons.compress.archivers.ArchiveInputStream;
44
import org.apache.commons.compress.archivers.ArchiveOutputStream;
45
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
46
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
47
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
48
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
49
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
50
import org.apache.commons.compress.archivers.zip.ZipFile;
51
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
52
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
53
import org.apache.commons.compress.compressors.gzip.GzipParameters;
54
import org.apache.commons.io.IOUtils;
55
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
57

58
import com.devonfw.tools.ide.cli.CliException;
59
import com.devonfw.tools.ide.context.IdeContext;
60
import com.devonfw.tools.ide.io.ini.IniComment;
61
import com.devonfw.tools.ide.io.ini.IniFile;
62
import com.devonfw.tools.ide.io.ini.IniSection;
63
import com.devonfw.tools.ide.os.SystemInfoImpl;
64
import com.devonfw.tools.ide.process.ProcessContext;
65
import com.devonfw.tools.ide.process.ProcessMode;
66
import com.devonfw.tools.ide.process.ProcessResult;
67
import com.devonfw.tools.ide.util.DateTimeUtil;
68
import com.devonfw.tools.ide.util.FilenameUtil;
69
import com.devonfw.tools.ide.util.HexUtil;
70
import com.devonfw.tools.ide.variable.IdeVariables;
71

72
/**
73
 * Implementation of {@link FileAccess}.
74
 */
75
public class FileAccessImpl extends HttpDownloader implements FileAccess {
76

77
  private static final Logger LOG = LoggerFactory.getLogger(FileAccessImpl.class);
4✔
78

79
  private static final String WINDOWS_FILE_LOCK_DOCUMENTATION_PAGE = "https://github.com/devonfw/IDEasy/blob/main/documentation/windows-file-lock.adoc";
80

81
  private static final String WINDOWS_FILE_LOCK_WARNING =
82
      "On Windows, file operations could fail due to file locks. Please ensure the files in the moved directory are not in use. For further details, see: \n"
83
          + WINDOWS_FILE_LOCK_DOCUMENTATION_PAGE;
84

85
  private final IdeContext context;
86

87
  /**
88
   * The constructor.
89
   *
90
   * @param context the {@link IdeContext} to use.
91
   */
92
  public FileAccessImpl(IdeContext context) {
93

94
    super();
2✔
95
    this.context = context;
3✔
96
  }
1✔
97

98
  @Override
99
  public void download(String url, Path target) {
100

101
    if (url.startsWith("http")) {
4✔
102
      downloadViaHttp(url, target);
5✔
103
    } else if (url.startsWith("ftp") || url.startsWith("sftp")) {
8!
104
      throw new IllegalArgumentException("Unsupported download URL: " + url);
×
105
    } else {
106
      Path source = Path.of(url);
5✔
107
      if (isFile(source)) {
4!
108
        // network drive
109
        copyFileWithProgressBar(source, target);
5✔
110
      } else {
111
        throw new IllegalArgumentException("Download path does not point to a downloadable file: " + url);
×
112
      }
113
    }
114
  }
1✔
115

116
  private void downloadViaHttp(String url, Path target) {
117

118
    List<Version> httpProtocols = IdeVariables.HTTP_VERSIONS.get(this.context);
6✔
119
    Exception lastException = null;
2✔
120
    if (httpProtocols.isEmpty()) {
3!
121
      try {
122
        downloadWithHttpVersion(url, target, null);
5✔
123
        return;
1✔
124
      } catch (Exception e) {
×
125
        lastException = e;
×
126
      }
×
127
    } else {
128
      for (Version version : httpProtocols) {
×
129
        try {
130
          downloadWithHttpVersion(url, target, version);
×
131
          return;
×
132
        } catch (Exception ex) {
×
133
          lastException = ex;
×
134
        }
135
      }
×
136
    }
137
    throw new IllegalStateException("Failed to download file from URL " + url + " to " + target, lastException);
×
138
  }
139

140
  private void downloadWithHttpVersion(String url, Path target, Version httpVersion) throws Exception {
141

142
    if (httpVersion == null) {
2!
143
      LOG.info("Trying to download {} from {}", target.getFileName(), url);
7✔
144
    } else {
145
      LOG.info("Trying to download {} from {} with HTTP protocol version {}", target.getFileName(), url, httpVersion);
×
146
    }
147
    mkdirs(target.getParent());
4✔
148
    this.context.getNetworkStatus().invokeNetworkTask(() ->
11✔
149
    {
150
      httpGet(url, httpVersion, (response) -> downloadFileWithProgressBar(url, target, response));
13✔
151
      return null;
2✔
152
    }, url);
153
  }
1✔
154

155
  /**
156
   * Downloads a file while showing a {@link IdeProgressBar}.
157
   *
158
   * @param url the url to download.
159
   * @param target Path of the target directory.
160
   * @param response the {@link HttpResponse} to use.
161
   */
162
  private void downloadFileWithProgressBar(String url, Path target, HttpResponse<InputStream> response) {
163

164
    long contentLength = response.headers().firstValueAsLong("content-length").orElse(-1);
7✔
165
    if (contentLength < 0) {
4✔
166
      LOG.warn("Content-Length was not provided by download from {}", url);
4✔
167
    }
168

169
    byte[] data = new byte[1024];
3✔
170
    boolean fileComplete = false;
2✔
171
    int count;
172

173
    try (InputStream body = response.body();
4✔
174
        FileOutputStream fileOutput = new FileOutputStream(target.toFile());
6✔
175
        BufferedOutputStream bufferedOut = new BufferedOutputStream(fileOutput, data.length);
7✔
176
        IdeProgressBar pb = this.context.newProgressBarForDownload(contentLength)) {
5✔
177
      while (!fileComplete) {
2✔
178
        count = body.read(data);
4✔
179
        if (count <= 0) {
2✔
180
          fileComplete = true;
3✔
181
        } else {
182
          bufferedOut.write(data, 0, count);
5✔
183
          pb.stepBy(count);
5✔
184
        }
185
      }
186
    } catch (Exception e) {
×
187
      throw new RuntimeException(e);
×
188
    }
1✔
189
  }
1✔
190

191
  private void copyFileWithProgressBar(Path source, Path target) {
192

193
    long size = getFileSize(source);
4✔
194
    if (size < 100_000) {
4✔
195
      copy(source, target, FileCopyMode.COPY_FILE_TO_TARGET_OVERRIDE);
5✔
196
      return;
1✔
197
    }
198
    try (InputStream in = Files.newInputStream(source); OutputStream out = Files.newOutputStream(target)) {
10✔
199
      byte[] buf = new byte[1024];
3✔
200
      try (IdeProgressBar pb = this.context.newProgressbarForCopying(size)) {
5✔
201
        int readBytes;
202
        while ((readBytes = in.read(buf)) > 0) {
6✔
203
          out.write(buf, 0, readBytes);
5✔
204
          pb.stepBy(readBytes);
5✔
205
        }
206
      } catch (Exception e) {
×
207
        throw new RuntimeException(e);
×
208
      }
1✔
209
    } catch (IOException e) {
×
210
      throw new RuntimeException("Failed to copy from " + source + " to " + target, e);
×
211
    }
1✔
212
  }
1✔
213

214
  @Override
215
  public String download(String url) {
216

217
    LOG.debug("Downloading text body from {}", url);
4✔
218
    return httpGetAsString(url);
3✔
219
  }
220

221
  @Override
222
  public void mkdirs(Path directory) {
223

224
    if (Files.isDirectory(directory)) {
5✔
225
      return;
1✔
226
    }
227
    LOG.trace("Creating directory {}", directory);
4✔
228
    try {
229
      Files.createDirectories(directory);
5✔
230
    } catch (IOException e) {
×
231
      throw new IllegalStateException("Failed to create directory " + directory, e);
×
232
    }
1✔
233
  }
1✔
234

235
  @Override
236
  public boolean isFile(Path file) {
237

238
    if (!Files.exists(file)) {
5!
239
      LOG.trace("File {} does not exist", file);
×
240
      return false;
×
241
    }
242
    if (Files.isDirectory(file)) {
5!
243
      LOG.trace("Path {} is a directory but a regular file was expected", file);
×
244
      return false;
×
245
    }
246
    return true;
2✔
247
  }
248

249
  @Override
250
  public boolean isExpectedFolder(Path folder) {
251

252
    if (Files.isDirectory(folder)) {
5✔
253
      return true;
2✔
254
    }
255
    LOG.warn("Expected folder was not found at {}", folder);
4✔
256
    return false;
2✔
257
  }
258

259
  @Override
260
  public String checksum(Path file, String hashAlgorithm) {
261

262
    MessageDigest md;
263
    try {
264
      md = MessageDigest.getInstance(hashAlgorithm);
3✔
265
    } catch (NoSuchAlgorithmException e) {
×
266
      throw new IllegalStateException("No such hash algorithm " + hashAlgorithm, e);
×
267
    }
1✔
268
    byte[] buffer = new byte[1024];
3✔
269
    try (InputStream is = Files.newInputStream(file); DigestInputStream dis = new DigestInputStream(is, md)) {
11✔
270
      int read = 0;
2✔
271
      while (read >= 0) {
2✔
272
        read = dis.read(buffer);
5✔
273
      }
274
    } catch (Exception e) {
×
275
      throw new IllegalStateException("Failed to read and hash file " + file, e);
×
276
    }
1✔
277
    byte[] digestBytes = md.digest();
3✔
278
    return HexUtil.toHexString(digestBytes);
3✔
279
  }
280

281
  @Override
282
  public boolean isJunction(Path path) {
283

284
    if (!SystemInfoImpl.INSTANCE.isWindows()) {
3!
285
      return false;
2✔
286
    }
287
    try {
288
      BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
×
289
      return attr.isOther() && attr.isDirectory();
×
290
    } catch (NoSuchFileException e) {
×
291
      return false; // file doesn't exist
×
292
    } catch (IOException e) {
×
293
      // For broken junctions, reading attributes might fail with various IOExceptions.
294
      // In such cases, we should check if the path exists without following links.
295
      // If it exists but we can't read its attributes, it's likely a broken junction.
296
      if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
×
297
        LOG.debug("Path {} exists but attributes cannot be read, likely a broken junction: {}", path, e.getMessage());
×
298
        return true; // Assume it's a broken junction
×
299
      }
300
      // If it doesn't exist at all, it's not a junction
301
      return false;
×
302
    }
303
  }
304

305
  @Override
306
  public Path backup(Path fileOrFolder) {
307

308
    if ((fileOrFolder != null) && (Files.isSymbolicLink(fileOrFolder) || isJunction(fileOrFolder))) {
9!
309
      delete(fileOrFolder);
4✔
310
    } else if ((fileOrFolder != null) && Files.exists(fileOrFolder)) {
7!
311
      LOG.trace("Going to backup {}", fileOrFolder);
4✔
312
      LocalDateTime now = LocalDateTime.now();
2✔
313
      String date = DateTimeUtil.formatDate(now, true);
4✔
314
      String time = DateTimeUtil.formatTime(now);
3✔
315
      String filename = fileOrFolder.getFileName().toString();
4✔
316
      Path backupBaseDir = this.context.getIdeHome();
4✔
317
      if (backupBaseDir == null) {
2!
318
        backupBaseDir = this.context.getIdePath();
×
319
      }
320
      Path backupPath = backupBaseDir.resolve(IdeContext.FOLDER_BACKUPS).resolve(date).resolve(time + "_" + filename);
10✔
321
      backupPath = appendParentPath(backupPath, fileOrFolder.getParent(), 2);
6✔
322
      mkdirs(backupPath);
3✔
323
      Path target = backupPath.resolve(filename);
4✔
324
      LOG.info("Creating backup by moving {} to {}", fileOrFolder, target);
5✔
325
      move(fileOrFolder, target);
6✔
326
      return target;
2✔
327
    } else {
328
      LOG.trace("Backup of {} skipped as the path does not exist.", fileOrFolder);
4✔
329
    }
330
    return fileOrFolder;
2✔
331
  }
332

333
  private static Path appendParentPath(Path path, Path parent, int max) {
334

335
    if ((parent == null) || (max <= 0)) {
4!
336
      return path;
2✔
337
    }
338
    return appendParentPath(path, parent.getParent(), max - 1).resolve(parent.getFileName());
11✔
339
  }
340

341
  @Override
342
  public void move(Path source, Path targetDir, StandardCopyOption... copyOptions) {
343

344
    LOG.trace("Moving {} to {}", source, targetDir);
5✔
345
    try {
346
      Files.move(source, targetDir, copyOptions);
5✔
347
    } catch (IOException e) {
×
348
      String fileType = Files.isSymbolicLink(source) ? "symlink" : isJunction(source) ? "junction" : Files.isDirectory(source) ? "directory" : "file";
×
349
      String message = "Failed to move " + fileType + ": " + source + " to " + targetDir + ".";
×
350
      if (this.context.getSystemInfo().isWindows()) {
×
351
        message = message + "\n" + WINDOWS_FILE_LOCK_WARNING;
×
352
      }
353
      throw new IllegalStateException(message, e);
×
354
    }
1✔
355
  }
1✔
356

357
  @Override
358
  public void copy(Path source, Path target, FileCopyMode mode, PathCopyListener listener) {
359

360
    if (mode.isUseSourceFilename()) {
3✔
361
      // if we want to copy the file or folder "source" to the existing folder "target" in a shell this will copy
362
      // source into that folder so that we as a result have a copy in "target/source".
363
      // With Java NIO the raw copy method will fail as we cannot copy "source" to the path of the "target" folder.
364
      // For folders we want the same behavior as the linux "cp -r" command so that the "source" folder is copied
365
      // and not only its content what also makes it consistent with the move method that also behaves this way.
366
      // Therefore we need to add the filename (foldername) of "source" to the "target" path before.
367
      // For the rare cases, where we want to copy the content of a folder (cp -r source/* target) we support
368
      // it via the COPY_TREE_CONTENT mode.
369
      Path fileName = source.getFileName();
3✔
370
      if (fileName != null) { // if filename is null, we are copying the root of a (virtual filesystem)
2!
371
        target = target.resolve(fileName.toString());
5✔
372
      }
373
    }
374
    boolean fileOnly = mode.isFileOnly();
3✔
375
    String operation = mode.getOperation();
3✔
376
    if (mode.isExtract()) {
3!
377
      LOG.debug("Starting to {} to {}", operation, target);
×
378
    } else {
379
      if (fileOnly) {
2✔
380
        LOG.debug("Starting to {} file {} to {}", operation, source, target);
18✔
381
      } else {
382
        LOG.debug("Starting to {} {} recursively to {}", operation, source, target);
17✔
383
      }
384
    }
385
    if (fileOnly && Files.isDirectory(source)) {
7!
386
      throw new IllegalStateException("Expected file but found a directory to copy at " + source);
×
387
    }
388
    if (mode.isFailIfExists()) {
3✔
389
      if (Files.exists(target)) {
5!
390
        throw new IllegalStateException("Failed to " + operation + " " + source + " to already existing target " + target);
×
391
      }
392
    } else if (mode == FileCopyMode.COPY_TREE_OVERRIDE_TREE) {
3✔
393
      delete(target);
3✔
394
    }
395
    try {
396
      copyRecursive(source, target, mode, listener);
6✔
397
    } catch (IOException e) {
×
398
      throw new IllegalStateException("Failed to " + operation + " " + source + " to " + target, e);
×
399
    }
1✔
400
  }
1✔
401

402
  private void copyRecursive(Path source, Path target, FileCopyMode mode, PathCopyListener listener) throws IOException {
403

404
    if (Files.isDirectory(source)) {
5✔
405
      mkdirs(target);
3✔
406
      try (Stream<Path> childStream = Files.list(source)) {
3✔
407
        Iterator<Path> iterator = childStream.iterator();
3✔
408
        while (iterator.hasNext()) {
3✔
409
          Path child = iterator.next();
4✔
410
          copyRecursive(child, target.resolve(child.getFileName().toString()), mode, listener);
10✔
411
        }
1✔
412
      }
413
      listener.onCopy(source, target, true);
6✔
414
    } else if (Files.exists(source)) {
5!
415
      if (mode.isOverride()) {
3✔
416
        delete(target);
3✔
417
      }
418
      LOG.trace("Starting to {} {} to {}", mode.getOperation(), source, target);
18✔
419
      Files.copy(source, target);
6✔
420
      listener.onCopy(source, target, false);
6✔
421
    } else {
422
      throw new IOException("Path " + source + " does not exist.");
×
423
    }
424
  }
1✔
425

426
  /**
427
   * Deletes the given {@link Path} if it is a symbolic link or a Windows junction. And throws an {@link IllegalStateException} if there is a file at the given
428
   * {@link Path} that is neither a symbolic link nor a Windows junction.
429
   *
430
   * @param path the {@link Path} to delete.
431
   */
432
  private void deleteLinkIfExists(Path path) {
433

434
    boolean isJunction = isJunction(path); // since broken junctions are not detected by Files.exists()
4✔
435
    boolean isSymlink = Files.exists(path, LinkOption.NOFOLLOW_LINKS) && Files.isSymbolicLink(path);
16!
436

437
    assert !(isSymlink && isJunction);
5!
438

439
    if (isJunction || isSymlink) {
4!
440
      LOG.info("Deleting previous " + (isJunction ? "junction" : "symlink") + " at " + path);
8!
441
      try {
442
        Files.delete(path);
2✔
443
      } catch (IOException e) {
×
444
        throw new IllegalStateException("Failed to delete link at " + path, e);
×
445
      }
1✔
446
    }
447
  }
1✔
448

449
  /**
450
   * Adapts the given {@link Path} to be relative or absolute depending on the given {@code relative} flag. Additionally, {@link Path#toRealPath(LinkOption...)}
451
   * is applied to {@code target}.
452
   *
453
   * @param link the {@link Path} the link should point to and that is to be adapted.
454
   * @param source the {@link Path} to the link. It is used to calculate the relative path to the {@code target} if {@code relative} is set to
455
   *     {@code true}.
456
   * @param relative the {@code relative} flag.
457
   * @return the adapted {@link Path}.
458
   * @see #symlink(Path, Path, boolean)
459
   */
460
  private Path adaptPath(Path source, Path link, boolean relative) {
461

462
    if (!source.isAbsolute()) {
3✔
463
      source = link.resolveSibling(source);
4✔
464
    }
465
    try {
466
      source = source.toRealPath(LinkOption.NOFOLLOW_LINKS); // to transform ../d1/../d2 to ../d2
9✔
467
    } catch (IOException e) {
×
468
      throw new RuntimeException("Failed to get real path of " + source, e);
×
469
    }
1✔
470
    if (relative) {
2✔
471
      source = link.getParent().relativize(source);
5✔
472
      // to make relative links like this work: dir/link -> dir
473
      source = (source.toString().isEmpty()) ? Path.of(".") : source;
11✔
474
    }
475
    return source;
2✔
476
  }
477

478
  /**
479
   * Creates a Windows link using mklink at {@code link} pointing to {@code target}.
480
   *
481
   * @param source the {@link Path} the link will point to.
482
   * @param link the {@link Path} where to create the link.
483
   * @param type the {@link PathLinkType}.
484
   */
485
  private void mklinkOnWindows(Path source, Path absoluteSource, Path link, PathLinkType type, boolean relative) {
486

487
    Path finalSource = source;
×
488
    Path finalLink = link;
×
489
    Path cwd = null;
×
490
    if (relative) {
×
491
      int count = getCommonNameCount(absoluteSource, link);
×
492
      if (count < 1) {
×
493
        LOG.error("Cannot create relative link at {} pointing to {} - falling back to absolute link", link, absoluteSource);
×
494
      } else {
495
        cwd = getPathStart(absoluteSource, count - 1);
×
496
        finalSource = getPathEnd(absoluteSource, count);
×
497
        finalLink = getPathEnd(link, count);
×
498
      }
499
    }
500

501
    String option = type.getMklinkOption();
×
502
    if (type == PathLinkType.SYMBOLIC_LINK) {
×
503
      boolean directoryTarget = Files.isDirectory(absoluteSource);
×
504
      option = directoryTarget ? "/j" : "/d";
×
505
    }
506

507
    if (!runMklink(finalSource, finalLink, cwd, option)) {
×
508
      throw new IllegalStateException("Failed to create Windows link at " + link + " pointing to " + source);
×
509
    }
510
  }
×
511

512
  private boolean runMklink(Path source, Path link, Path cwd, String option) {
513

514
    LOG.trace("Creating a Windows link with mklink {} at {} pointing to {}", option, link, source);
×
515
    ProcessContext pc = this.context.newProcess().executable("cmd").addArgs("/c", "mklink", option);
×
516
    if (cwd != null) {
×
517
      pc.directory(cwd);
×
518
    }
519
    ProcessResult result = pc.addArgs(link.toString(), source.toString()).run(ProcessMode.DEFAULT);
×
520
    try {
521
      result.failOnError();
×
522
      return true;
×
523
    } catch (RuntimeException e) {
×
524
      LOG.debug("mklink {} failed for {} -> {}: {}", option, link, source, e.getMessage());
×
525
      return false;
×
526
    }
527
  }
528

529
  @Override
530
  public void link(Path source, Path link, boolean relative, PathLinkType type) {
531

532
    Path finalLink = link.toAbsolutePath().normalize();
4✔
533
    Path finalSource;
534
    try {
535
      finalSource = adaptPath(source, finalLink, relative);
6✔
536
    } catch (Exception e) {
×
537
      throw new IllegalStateException("Failed to adapt target (" + source + ") for link (" + finalLink + ") and relative (" + relative + ")", e);
×
538
    }
1✔
539
    Path absoluteSource = finalSource.isAbsolute() ? finalSource : finalLink.getParent().resolve(finalSource).normalize();
11✔
540
    String relativeOrAbsolute = relative ? "relative" : "absolute";
6✔
541
    LOG.debug("Creating {} {} at {} pointing to {}", relativeOrAbsolute, type, finalLink, finalSource);
21✔
542
    deleteLinkIfExists(finalLink);
3✔
543
    try {
544
      // Attention: JavaDoc and position of path arguments can be very confusing - see comment in #1736
545
      if (type == PathLinkType.SYMBOLIC_LINK) {
3!
546
        Files.createSymbolicLink(finalLink, finalSource);
7✔
547
      } else if (type == PathLinkType.HARD_LINK) {
×
548
        Files.createLink(finalLink, finalSource);
×
549
      } else {
550
        throw new IllegalStateException("" + type);
×
551
      }
552
    } catch (FileSystemException e) {
×
553
      if (SystemInfoImpl.INSTANCE.isWindows()) {
×
554
        LOG.info(
×
555
            "Due to lack of permissions, Microsoft's mklink with junction had to be used to create a Symlink. See\n"
556
                + "https://github.com/devonfw/IDEasy/blob/main/documentation/symlink.adoc for further details. Error was: "
557
                + e.getMessage());
×
558
        mklinkOnWindows(finalSource, absoluteSource, finalLink, type, relative);
×
559
      } else {
560
        throw new RuntimeException(e);
×
561
      }
562
    } catch (IOException e) {
×
563
      throw new IllegalStateException("Failed to create a " + relativeOrAbsolute + " " + type + " at " + finalLink + " pointing to " + source, e);
×
564
    }
1✔
565
  }
1✔
566

567
  @Override
568
  public Path getPathStart(Path path, int nameEnd) {
569

570
    int count = path.getNameCount();
3✔
571
    int delta = count - nameEnd - 1;
6✔
572
    if (delta < 0) {
2!
573
      throw new IllegalArgumentException("Cannot get start before segment " + nameEnd + " from path " + path + " that has only " + count + " segments.");
×
574
    }
575
    Path result = path;
2✔
576
    while (delta > 0) {
2✔
577
      result = result.getParent();
3✔
578
      delta--;
2✔
579
    }
580
    return result;
2✔
581
  }
582

583
  @Override
584
  public Path getPathEnd(Path path, int nameStart) {
585

586
    int count = path.getNameCount();
3✔
587
    if (nameStart > count) {
3!
588
      throw new IllegalArgumentException("Cannot get end after segment " + nameStart + " from path " + path + " that has only " + count + " segments.");
×
589
    } else if (nameStart == count) {
3!
590
      return Path.of(".");
×
591
    }
592
    Path result = path.getName(nameStart++);
5✔
593
    while (nameStart < count) {
3✔
594
      result = result.resolve(path.getName(nameStart++));
8✔
595
    }
596
    return result;
2✔
597
  }
598

599
  @Override
600
  public int getCommonNameCount(Path path1, Path path2) {
601

602
    if ((path1 == null) || (path2 == null) || !Objects.equals(path1.getRoot(), path2.getRoot())) {
10✔
603
      return -1;
2✔
604
    }
605
    int minNameCount = Math.min(path1.getNameCount(), path2.getNameCount());
6✔
606
    int i = 0;
2✔
607
    while (i < minNameCount) {
3!
608
      Path segment1 = path1.getName(i);
4✔
609
      Path segment2 = path2.getName(i);
4✔
610
      if (!segment1.equals(segment2)) {
4✔
611
        break;
1✔
612
      }
613
      i++;
1✔
614
    }
1✔
615
    return i;
2✔
616
  }
617

618
  @Override
619
  public Path toRealPath(Path path) {
620

621
    return toRealPath(path, true);
5✔
622
  }
623

624
  @Override
625
  public Path toCanonicalPath(Path path) {
626

627
    return toRealPath(path, false);
5✔
628
  }
629

630
  private Path toRealPath(Path path, boolean resolveLinks) {
631

632
    try {
633
      Path realPath;
634
      if (resolveLinks) {
2✔
635
        realPath = path.toRealPath();
6✔
636
      } else {
637
        realPath = path.toRealPath(LinkOption.NOFOLLOW_LINKS);
9✔
638
      }
639
      if (!realPath.equals(path)) {
4✔
640
        LOG.trace("Resolved path {} to {}", path, realPath);
5✔
641
      }
642
      return realPath;
2✔
643
    } catch (IOException e) {
×
644
      throw new IllegalStateException("Failed to get real path for " + path, e);
×
645
    }
646
  }
647

648
  @Override
649
  public Path createTempDir(String name) {
650

651
    try {
652
      Path tmp = this.context.getTempPath();
4✔
653
      Path tempDir = tmp.resolve(name);
4✔
654
      int tries = 1;
2✔
655
      while (Files.exists(tempDir)) {
5!
656
        long id = System.nanoTime() & 0xFFFF;
×
657
        tempDir = tmp.resolve(name + "-" + id);
×
658
        tries++;
×
659
        if (tries > 200) {
×
660
          throw new IOException("Unable to create unique name!");
×
661
        }
662
      }
×
663
      return Files.createDirectory(tempDir);
5✔
664
    } catch (IOException e) {
×
665
      throw new IllegalStateException("Failed to create temporary directory with prefix '" + name + "'!", e);
×
666
    }
667
  }
668

669
  @Override
670
  public void extract(Path archiveFile, Path targetDir, Consumer<Path> postExtractHook, boolean extract) {
671

672
    if (Files.isDirectory(archiveFile)) {
5✔
673
      LOG.warn("Found directory for download at {} hence copying without extraction!", archiveFile);
4✔
674
      copy(archiveFile, targetDir, FileCopyMode.COPY_TREE_CONTENT);
5✔
675
      postExtractHook(postExtractHook, targetDir);
4✔
676
      return;
1✔
677
    } else if (!extract) {
2✔
678
      mkdirs(targetDir);
3✔
679
      move(archiveFile, targetDir.resolve(archiveFile.getFileName()));
9✔
680
      return;
1✔
681
    }
682
    Path tmpDir = createTempDir("extract-" + archiveFile.getFileName());
7✔
683
    LOG.trace("Trying to extract the file {} to {} and move it to {}.", archiveFile, tmpDir, targetDir);
17✔
684
    String filename = archiveFile.getFileName().toString();
4✔
685
    TarCompression tarCompression = TarCompression.of(filename);
3✔
686
    if (tarCompression != null) {
2✔
687
      extractTar(archiveFile, tmpDir, tarCompression);
6✔
688
    } else {
689
      String extension = FilenameUtil.getExtension(filename);
3✔
690
      if (extension == null) {
2!
691
        throw new IllegalStateException("Unknown archive format without extension - can not extract " + archiveFile);
×
692
      } else {
693
        LOG.trace("Determined file extension {}", extension);
4✔
694
      }
695
      switch (extension) {
8!
696
        case "zip" -> extractZip(archiveFile, tmpDir);
×
697
        case "jar" -> extractJar(archiveFile, tmpDir);
5✔
698
        case "dmg" -> extractDmg(archiveFile, tmpDir);
×
699
        case "msi" -> extractMsi(archiveFile, tmpDir);
×
700
        case "pkg" -> extractPkg(archiveFile, tmpDir);
×
701
        default -> throw new IllegalStateException("Unknown archive format " + extension + ". Can not extract " + archiveFile);
×
702
      }
703
    }
704
    Path properInstallDir = getProperInstallationSubDirOf(tmpDir, archiveFile);
5✔
705
    postExtractHook(postExtractHook, properInstallDir);
4✔
706
    move(properInstallDir, targetDir);
6✔
707
    delete(tmpDir);
3✔
708
  }
1✔
709

710
  private void postExtractHook(Consumer<Path> postExtractHook, Path properInstallDir) {
711

712
    if (postExtractHook != null) {
2✔
713
      postExtractHook.accept(properInstallDir);
3✔
714
    }
715
  }
1✔
716

717
  /**
718
   * @param path the {@link Path} to start the recursive search from.
719
   * @return the deepest subdir {@code s} of the passed path such that all directories between {@code s} and the passed path (including {@code s}) are the sole
720
   *     item in their respective directory and {@code s} is not named "bin".
721
   */
722
  private Path getProperInstallationSubDirOf(Path path, Path archiveFile) {
723

724
    try (Stream<Path> stream = Files.list(path)) {
3✔
725
      Path[] subFiles = stream.toArray(Path[]::new);
8✔
726
      if (subFiles.length == 0) {
3!
727
        throw new CliException("The downloaded package " + archiveFile + " seems to be empty as you can check in the extracted folder " + path);
×
728
      } else if (subFiles.length == 1) {
4✔
729
        String filename = subFiles[0].getFileName().toString();
6✔
730
        if (!filename.equals(IdeContext.FOLDER_BIN) && !filename.equals(IdeContext.FOLDER_CONTENTS) && !filename.endsWith(".app") && Files.isDirectory(
19!
731
            subFiles[0])) {
732
          return getProperInstallationSubDirOf(subFiles[0], archiveFile);
9✔
733
        }
734
      }
735
      return path;
4✔
736
    } catch (IOException e) {
4!
737
      throw new IllegalStateException("Failed to get sub-files of " + path);
×
738
    }
739
  }
740

741
  @Override
742
  public void extractZip(Path file, Path targetDir) {
743

744
    LOG.info("Extracting ZIP file {} to {}", file, targetDir);
5✔
745
    extractZipWithJava(file, targetDir);
4✔
746
  }
1✔
747

748
  /**
749
   * Extracts a ZIP archive to the given target directory using Java (commons-compress {@link ZipFile}).
750
   * <p>
751
   * Symlinks are handled in a two-phase approach: all regular files and directories are written first, and symlinks are
752
   * collected and created afterwards. This ensures every symlink target already exists on disk before the link is made.
753
   * <p>
754
   * {@link ZipFile} is used instead of {@link org.apache.commons.compress.archivers.zip.ZipArchiveInputStream} because
755
   * Unix file attributes (needed for symlink detection and permission restoration) are stored in the ZIP central
756
   * directory at the end of the file. A sequential stream only sees the local file headers, where external attributes
757
   * are always zero. {@link ZipFile} reads the central directory via random access, so attributes are always correct.
758
   *
759
   * @param file the ZIP archive to extract.
760
   * @param targetDir the directory to extract into.
761
   */
762
  private void extractZipWithJava(Path file, Path targetDir) {
763

764
    final List<PathLink> links = new ArrayList<>();
4✔
765
    try (ZipFile zipFile = ZipFile.builder().setPath(file).get();
6✔
766
        IdeProgressBar pb = this.context.newProgressbarForExtracting(getFileSize(file))) {
7✔
767

768
      final Path root = targetDir.toAbsolutePath().normalize();
4✔
769
      Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
3✔
770

771
      while (entries.hasMoreElements()) {
3✔
772
        ZipArchiveEntry entry = entries.nextElement();
4✔
773
        String entryName = entry.getName();
3✔
774
        Path entryPath = resolveRelativePathSecure(entryName, root);
5✔
775

776
        if (isZipSymlink(entry)) {
3✔
777
          try (InputStream entryStream = zipFile.getInputStream(entry)) {
5✔
778
            // For symlink entries the file content IS the link target path (Unix zip convention).
779
            String linkTarget = IOUtils.toString(entryStream, StandardCharsets.UTF_8);
4✔
780
            Path parent = entryPath.getParent();
3✔
781
            Path source = parent.resolve(linkTarget).normalize();
5✔
782
            resolveRelativePathSecure(source, root, linkTarget);
6✔
783
            links.add(new PathLink(source, entryPath, PathLinkType.SYMBOLIC_LINK));
9✔
784
            mkdirs(parent);
3✔
785
          }
786
        } else if (entry.isDirectory()) {
3✔
787
          mkdirs(entryPath);
4✔
788
        } else {
789
          mkdirs(entryPath.getParent());
4✔
790
          try (InputStream entryStream = zipFile.getInputStream(entry)) {
4✔
791
            Files.copy(entryStream, entryPath, StandardCopyOption.REPLACE_EXISTING);
10✔
792
          }
793
          onFileCopiedFromZip(entry, entryPath);
4✔
794
        }
795
        pb.stepBy(Math.max(0L, entry.getSize()));
6✔
796
      }
1✔
797

798
      // Phase 2: create all symlinks now that their targets are guaranteed to exist.
799
      for (PathLink link : links) {
10✔
800
        link(link);
3✔
801
      }
1✔
802
    } catch (IOException e) {
×
803
      throw new IllegalStateException("Failed to extract " + file + " to " + targetDir, e);
×
804
    }
1✔
805
  }
1✔
806

807
  /**
808
   * Returns the Unix file mode stored in the external file attributes of the given ZIP entry.
809
   * <p>
810
   * The ZIP specification stores platform-specific metadata in a 32-bit external-attributes field. When the archive was
811
   * created on a Unix system the layout is:
812
   * <ul>
813
   *   <li>bits 31–16 (upper 16 bits): Unix file mode (same bit layout as {@code stat.st_mode})</li>
814
   *   <li>bits 15–0 (lower 16 bits): MS-DOS attributes (read-only, hidden, …)</li>
815
   * </ul>
816
   * Shifting right by 16 and masking with {@code 0xFFFF} isolates the Unix mode.
817
   *
818
   * @param entry the ZIP entry to read.
819
   * @return the Unix file mode, or {@code 0} if no Unix attributes are present.
820
   */
821
  private static int getZipUnixMode(ZipArchiveEntry entry) {
822

823
    // Right-shift by 16 to move the upper 16 bits (Unix mode) into the lower 16 bits, then
824
    // mask with 0xFFFF to discard any sign-extended bits introduced by the cast.
825
    return (int) ((entry.getExternalAttributes() >> 16) & 0xFFFF);
8✔
826
  }
827

828
  /**
829
   * Returns {@code true} if the given ZIP entry represents a symbolic link.
830
   * <p>
831
   * Unix file modes encode the file type in the top 4 bits (bits 15–12) of the mode word. The possible file-type
832
   * values are defined in {@code <sys/stat.h>}:
833
   * <ul>
834
   *   <li>{@code 0x8000} – regular file ({@code S_IFREG})</li>
835
   *   <li>{@code 0x4000} – directory ({@code S_IFDIR})</li>
836
   *   <li>{@code 0xA000} – symbolic link ({@code S_IFLNK})</li>
837
   * </ul>
838
   * Masking with {@code 0xF000} isolates those top 4 bits and comparing against {@code 0xA000} identifies symlinks.
839
   *
840
   * @param entry the ZIP entry to test.
841
   * @return {@code true} if the entry is a symbolic link, {@code false} otherwise.
842
   */
843
  private static boolean isZipSymlink(ZipArchiveEntry entry) {
844

845
    // 0xF000 masks the file-type nibble; 0xA000 is the Unix S_IFLNK constant.
846
    return (getZipUnixMode(entry) & 0xF000) == 0xA000;
10✔
847
  }
848

849
  /**
850
   * Applies Unix file permissions stored in a ZIP entry to the extracted file.
851
   * <p>
852
   * Permissions are only applied on non-Windows systems because POSIX permission bits have no equivalent on Windows.
853
   * If the entry carries no Unix attributes (mode is {@code 0}), the call is a no-op.
854
   *
855
   * @param entry the source ZIP entry carrying the Unix mode.
856
   * @param target the extracted file whose permissions should be updated.
857
   */
858
  private void onFileCopiedFromZip(ZipArchiveEntry entry, Path target) {
859

860
    if (!this.context.getSystemInfo().isWindows()) {
5✔
861
      try {
862
        int unixMode = getZipUnixMode(entry);
3✔
863
        if (unixMode != 0) {
2✔
864
          Files.setPosixFilePermissions(target, PathPermissions.of(unixMode).toPosix());
6✔
865
        }
866
      } catch (Exception e) {
×
867
        LOG.error("Failed to transfer zip permissions for {}", target, e);
×
868
      }
1✔
869
    }
870
  }
1✔
871

872
  @Override
873
  public void extractTar(Path file, Path targetDir, TarCompression compression) {
874

875
    extractArchive(file, targetDir, in -> new TarArchiveInputStream(compression.unpack(in)));
13✔
876
  }
1✔
877

878
  @Override
879
  public void extractJar(Path file, Path targetDir) {
880

881
    extractZip(file, targetDir);
4✔
882
  }
1✔
883

884
  /**
885
   * @param permissions The integer as returned by {@link TarArchiveEntry#getMode()} that represents the file permissions of a file on a Unix file system.
886
   * @return A String representing the file permissions. E.g. "rwxrwxr-x" or "rw-rw-r--"
887
   */
888
  public static String generatePermissionString(int permissions) {
889

890
    // Ensure that only the last 9 bits are considered
891
    permissions &= 0b111111111;
4✔
892

893
    StringBuilder permissionStringBuilder = new StringBuilder("rwxrwxrwx");
5✔
894
    for (int i = 0; i < 9; i++) {
7✔
895
      int mask = 1 << i;
4✔
896
      char currentChar = ((permissions & mask) != 0) ? permissionStringBuilder.charAt(8 - i) : '-';
12✔
897
      permissionStringBuilder.setCharAt(8 - i, currentChar);
6✔
898
    }
899

900
    return permissionStringBuilder.toString();
3✔
901
  }
902

903
  private void extractArchive(Path file, Path targetDir, Function<InputStream, ArchiveInputStream<?>> unpacker) {
904

905
    LOG.info("Extracting TAR file {} to {}", file, targetDir);
5✔
906

907
    final List<PathLink> links = new ArrayList<>();
4✔
908
    try (InputStream is = Files.newInputStream(file);
5✔
909
        ArchiveInputStream<?> ais = unpacker.apply(is);
5✔
910
        IdeProgressBar pb = this.context.newProgressbarForExtracting(getFileSize(file))) {
7✔
911

912
      final Path root = targetDir.toAbsolutePath().normalize();
4✔
913

914
      ArchiveEntry entry = ais.getNextEntry();
3✔
915
      while (entry != null) {
2✔
916
        String entryName = entry.getName();
3✔
917
        Path entryPath = resolveRelativePathSecure(entryName, root);
5✔
918
        PathPermissions permissions = null;
2✔
919
        PathLinkType linkType = null;
2✔
920
        if (entry instanceof TarArchiveEntry tae) {
6!
921
          if (tae.isSymbolicLink()) {
3✔
922
            linkType = PathLinkType.SYMBOLIC_LINK;
3✔
923
          } else if (tae.isLink()) {
3!
924
            linkType = PathLinkType.HARD_LINK;
×
925
          }
926
          if (linkType == null) {
2✔
927
            permissions = PathPermissions.of(tae.getMode());
5✔
928
          } else {
929
            Path parent = entryPath.getParent();
3✔
930
            String sourcePathString = tae.getLinkName();
3✔
931
            Path source = parent.resolve(sourcePathString).normalize();
5✔
932
            source = resolveRelativePathSecure(source, root, sourcePathString);
6✔
933
            links.add(new PathLink(source, entryPath, linkType));
9✔
934
            mkdirs(parent);
3✔
935
          }
936
        }
937
        if (entry.isDirectory()) {
3✔
938
          mkdirs(entryPath);
4✔
939
        } else if (linkType == null) { // regular file
2✔
940
          mkdirs(entryPath.getParent());
4✔
941
          Files.copy(ais, entryPath, StandardCopyOption.REPLACE_EXISTING);
10✔
942
          // POSIX perms on non-Windows
943
          if (permissions != null) {
2!
944
            setFilePermissions(entryPath, permissions, false);
5✔
945
          }
946
        }
947
        pb.stepBy(Math.max(0L, entry.getSize()));
6✔
948
        entry = ais.getNextEntry();
3✔
949
      }
1✔
950
      // post process links
951
      for (PathLink link : links) {
10✔
952
        link(link);
3✔
953
      }
1✔
954
    } catch (Exception e) {
×
955
      throw new IllegalStateException("Failed to extract " + file + " to " + targetDir, e);
×
956
    }
1✔
957
  }
1✔
958

959
  private Path resolveRelativePathSecure(String entryName, Path root) {
960

961
    Path entryPath = root.resolve(entryName).normalize();
5✔
962
    return resolveRelativePathSecure(entryPath, root, entryName);
6✔
963
  }
964

965
  private Path resolveRelativePathSecure(Path entryPath, Path root, String entryName) {
966

967
    if (!entryPath.startsWith(root)) {
4!
968
      throw new IllegalStateException("Preventing path traversal attack from " + entryName + " to " + entryPath + " leaving " + root);
×
969
    }
970
    return entryPath;
2✔
971
  }
972

973
  @Override
974
  public void extractDmg(Path file, Path targetDir) {
975

976
    LOG.info("Extracting DMG file {} to {}", file, targetDir);
×
977
    assert this.context.getSystemInfo().isMac();
×
978

979
    Path mountPath = this.context.getIdeHome().resolve(IdeContext.FOLDER_UPDATES).resolve(IdeContext.FOLDER_VOLUME);
×
980
    mkdirs(mountPath);
×
981
    ProcessContext pc = this.context.newProcess();
×
982
    pc.executable("hdiutil");
×
983
    pc.addArgs("attach", "-quiet", "-nobrowse", "-mountpoint", mountPath, file);
×
984
    pc.run();
×
985
    Path appPath = findFirst(mountPath, p -> p.getFileName().toString().endsWith(".app"), false);
×
986
    if (appPath == null) {
×
987
      throw new IllegalStateException("Failed to unpack DMG as no MacOS *.app was found in file " + file);
×
988
    }
989

990
    copy(appPath, targetDir, FileCopyMode.COPY_TREE_OVERRIDE_TREE);
×
991
    pc.addArgs("detach", "-force", mountPath);
×
992
    pc.run();
×
993
  }
×
994

995
  @Override
996
  public void extractMsi(Path file, Path targetDir) {
997

998
    LOG.info("Extracting MSI file {} to {}", file, targetDir);
×
999
    this.context.newProcess().executable("msiexec").addArgs("/a", file, "/qn", "TARGETDIR=" + targetDir).run();
×
1000
    // msiexec also creates a copy of the MSI
1001
    Path msiCopy = targetDir.resolve(file.getFileName());
×
1002
    delete(msiCopy);
×
1003
  }
×
1004

1005
  @Override
1006
  public void extractPkg(Path file, Path targetDir) {
1007

1008
    LOG.info("Extracting PKG file {} to {}", file, targetDir);
×
1009
    assert this.context.getSystemInfo().isMac();
×
1010
    Path tmpDirPkg = createTempDir("ide-pkg-");
×
1011
    ProcessContext pc = this.context.newProcess();
×
1012
    pc.executable("xar").addArgs("-C", tmpDirPkg, "-xf", file).run();
×
1013
    Path contentPath = findFirst(tmpDirPkg, p -> p.getFileName().toString().equals("Payload"), true);
×
1014
    extractPkgPayloadWithSystemTar(contentPath, targetDir);
×
1015
    delete(tmpDirPkg);
×
1016
  }
×
1017

1018
  private void extractPkgPayloadWithSystemTar(Path payload, Path targetDir) {
1019

1020
    mkdirs(targetDir);
×
1021
    ProcessContext pc = this.context.newProcess();
×
1022
    pc.executable("/usr/bin/tar");
×
1023
    pc.addArgs("-xf", payload, "-C", targetDir);
×
1024
    pc.run();
×
1025
  }
×
1026

1027
  @Override
1028
  public void compress(Path dir, OutputStream out, String path) {
1029

1030
    String extension = FilenameUtil.getExtension(path);
3✔
1031
    TarCompression tarCompression = TarCompression.of(extension);
3✔
1032
    if (tarCompression != null) {
2!
1033
      compressTar(dir, out, tarCompression);
6✔
1034
    } else if (extension.equals("zip")) {
×
1035
      compressZip(dir, out);
×
1036
    } else {
1037
      throw new IllegalArgumentException("Unsupported extension: " + extension);
×
1038
    }
1039
  }
1✔
1040

1041
  @Override
1042
  public void compressTar(Path dir, OutputStream out, TarCompression tarCompression) {
1043

1044
    switch (tarCompression) {
8!
1045
      case null -> compressTar(dir, out);
×
1046
      case NONE -> compressTar(dir, out);
×
1047
      case GZ -> compressTarGz(dir, out);
5✔
1048
      case BZIP2 -> compressTarBzip2(dir, out);
×
1049
      default -> throw new IllegalArgumentException("Unsupported tar compression: " + tarCompression);
×
1050
    }
1051
  }
1✔
1052

1053
  @Override
1054
  public void compressTarGz(Path dir, OutputStream out) {
1055

1056
    GzipParameters parameters = new GzipParameters();
4✔
1057
    parameters.setModificationTime(0);
3✔
1058
    try (GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(out, parameters)) {
6✔
1059
      compressTarOrThrow(dir, gzOut);
4✔
1060
    } catch (IOException e) {
×
1061
      throw new IllegalStateException("Failed to compress directory " + dir + " to tar.gz file.", e);
×
1062
    }
1✔
1063
  }
1✔
1064

1065
  @Override
1066
  public void compressTarBzip2(Path dir, OutputStream out) {
1067

1068
    try (BZip2CompressorOutputStream bzip2Out = new BZip2CompressorOutputStream(out)) {
×
1069
      compressTarOrThrow(dir, bzip2Out);
×
1070
    } catch (IOException e) {
×
1071
      throw new IllegalStateException("Failed to compress directory " + dir + " to tar.bz2 file.", e);
×
1072
    }
×
1073
  }
×
1074

1075
  @Override
1076
  public void compressTar(Path dir, OutputStream out) {
1077

1078
    try {
1079
      compressTarOrThrow(dir, out);
×
1080
    } catch (IOException e) {
×
1081
      throw new IllegalStateException("Failed to compress directory " + dir + " to tar file.", e);
×
1082
    }
×
1083
  }
×
1084

1085
  private void compressTarOrThrow(Path dir, OutputStream out) throws IOException {
1086

1087
    try (TarArchiveOutputStream tarOut = new TarArchiveOutputStream(out)) {
5✔
1088
      compressRecursive(dir, tarOut, "");
5✔
1089
      tarOut.finish();
2✔
1090
    }
1091
  }
1✔
1092

1093
  @Override
1094
  public void compressZip(Path dir, OutputStream out) {
1095

1096
    try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(out)) {
5✔
1097
      compressRecursive(dir, zipOut, "");
5✔
1098
      zipOut.finish();
2✔
1099
    } catch (IOException e) {
×
1100
      throw new IllegalStateException("Failed to compress directory " + dir + " to zip file.", e);
×
1101
    }
1✔
1102
  }
1✔
1103

1104
  private <E extends ArchiveEntry> void compressRecursive(Path path, ArchiveOutputStream<E> out, String relativePath) {
1105

1106
    try (Stream<Path> childStream = Files.list(path).sorted()) {
4✔
1107
      Iterator<Path> iterator = childStream.iterator();
3✔
1108
      while (iterator.hasNext()) {
3✔
1109
        Path child = iterator.next();
4✔
1110
        String relativeChildPath = relativePath + "/" + child.getFileName().toString();
6✔
1111
        boolean isDirectory = Files.isDirectory(child);
5✔
1112
        E archiveEntry = out.createArchiveEntry(child, relativeChildPath);
7✔
1113
        FileTime none = FileTime.fromMillis(0);
3✔
1114
        if (archiveEntry instanceof TarArchiveEntry tarEntry) {
6✔
1115
          tarEntry.setCreationTime(none);
3✔
1116
          tarEntry.setModTime(none);
3✔
1117
          tarEntry.setLastAccessTime(none);
3✔
1118
          tarEntry.setLastModifiedTime(none);
3✔
1119
          tarEntry.setUserId(0);
3✔
1120
          tarEntry.setUserName("user");
3✔
1121
          tarEntry.setGroupId(0);
3✔
1122
          tarEntry.setGroupName("group");
3✔
1123
          PathPermissions filePermissions = getFilePermissions(child);
4✔
1124
          tarEntry.setMode(filePermissions.toMode());
4✔
1125
        } else if (archiveEntry instanceof ZipArchiveEntry zipEntry) {
7!
1126
          zipEntry.setCreationTime(none);
4✔
1127
          zipEntry.setLastAccessTime(none);
4✔
1128
          zipEntry.setLastModifiedTime(none);
4✔
1129
          zipEntry.setTime(none);
3✔
1130
        }
1131
        out.putArchiveEntry(archiveEntry);
3✔
1132
        if (!isDirectory) {
2✔
1133
          try (InputStream in = Files.newInputStream(child)) {
5✔
1134
            IOUtils.copy(in, out);
4✔
1135
          }
1136
        }
1137
        out.closeArchiveEntry();
2✔
1138
        if (isDirectory) {
2✔
1139
          compressRecursive(child, out, relativeChildPath);
5✔
1140
        }
1141
      }
1✔
1142
    } catch (IOException e) {
×
1143
      throw new IllegalStateException("Failed to compress " + path, e);
×
1144
    }
1✔
1145
  }
1✔
1146

1147
  @Override
1148
  public void delete(Path path) {
1149

1150
    if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
9✔
1151
      LOG.trace("Deleting {} skipped as the path does not exist.", path);
4✔
1152
      return;
1✔
1153
    }
1154
    LOG.debug("Deleting {} ...", path);
4✔
1155
    try {
1156
      if (isLink(path)) {
4✔
1157
        deletePath(path);
4✔
1158
      } else {
1159
        deleteRecursive(path);
3✔
1160
      }
1161
    } catch (IOException e) {
×
1162
      throw new IllegalStateException("Failed to delete " + path, e);
×
1163
    }
1✔
1164
  }
1✔
1165

1166
  private void deleteRecursive(Path path) throws IOException {
1167

1168
    if (Files.isSymbolicLink(path) || isJunction(path)) {
7!
1169
      LOG.trace("Deleting link {} ...", path);
4✔
1170
      Files.delete(path);
2✔
1171
      return;
1✔
1172
    }
1173
    if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
9✔
1174
      try (Stream<Path> childStream = Files.list(path)) {
3✔
1175
        Iterator<Path> iterator = childStream.iterator();
3✔
1176
        while (iterator.hasNext()) {
3✔
1177
          Path child = iterator.next();
4✔
1178
          deleteRecursive(child);
3✔
1179
        }
1✔
1180
      }
1181
    }
1182
    deletePath(path);
3✔
1183
  }
1✔
1184

1185
  private boolean isLink(Path path) {
1186

1187
    return Files.isSymbolicLink(path) || isJunction(path);
11!
1188
  }
1189

1190
  private void deletePath(Path path) throws IOException {
1191

1192
    LOG.trace("Deleting {} ...", path);
4✔
1193
    boolean isSetWritable = setWritable(path, true);
5✔
1194
    if (!isSetWritable) {
2✔
1195
      LOG.debug("Couldn't give write access to file: {}", path);
4✔
1196
    }
1197
    Files.delete(path);
2✔
1198
  }
1✔
1199

1200
  @Override
1201
  public Path findFirst(Path dir, Predicate<Path> filter, boolean recursive) {
1202

1203
    try {
1204
      if (!Files.isDirectory(dir)) {
5!
1205
        return null;
×
1206
      }
1207
      return findFirstRecursive(dir, filter, recursive);
6✔
1208
    } catch (IOException e) {
×
1209
      throw new IllegalStateException("Failed to search for file in " + dir, e);
×
1210
    }
1211
  }
1212

1213
  private Path findFirstRecursive(Path dir, Predicate<Path> filter, boolean recursive) throws IOException {
1214

1215
    List<Path> folders = null;
2✔
1216
    try (Stream<Path> childStream = Files.list(dir)) {
3✔
1217
      Iterator<Path> iterator = childStream.iterator();
3✔
1218
      while (iterator.hasNext()) {
3✔
1219
        Path child = iterator.next();
4✔
1220
        if (filter.test(child)) {
4✔
1221
          return child;
4✔
1222
        } else if (recursive && Files.isDirectory(child)) {
2!
1223
          if (folders == null) {
×
1224
            folders = new ArrayList<>();
×
1225
          }
1226
          folders.add(child);
×
1227
        }
1228
      }
1✔
1229
    }
4!
1230
    if (folders != null) {
2!
1231
      for (Path child : folders) {
×
1232
        Path match = findFirstRecursive(child, filter, recursive);
×
1233
        if (match != null) {
×
1234
          return match;
×
1235
        }
1236
      }
×
1237
    }
1238
    return null;
2✔
1239
  }
1240

1241
  @Override
1242
  public Path findAncestor(Path path, Path baseDir, int subfolderCount) {
1243

1244
    if ((path == null) || (baseDir == null)) {
4!
1245
      LOG.debug("Path should not be null for findAncestor.");
3✔
1246
      return null;
2✔
1247
    }
1248
    if (subfolderCount <= 0) {
2!
1249
      throw new IllegalArgumentException("Subfolder count: " + subfolderCount);
×
1250
    }
1251
    // 1. option relativize
1252
    // 2. recursive getParent
1253
    // 3. loop getParent???
1254
    // 4. getName + getNameCount
1255
    path = path.toAbsolutePath().normalize();
4✔
1256
    baseDir = baseDir.toAbsolutePath().normalize();
4✔
1257
    int directoryNameCount = path.getNameCount();
3✔
1258
    int baseDirNameCount = baseDir.getNameCount();
3✔
1259
    int delta = directoryNameCount - baseDirNameCount - subfolderCount;
6✔
1260
    if (delta < 0) {
2!
1261
      return null;
×
1262
    }
1263
    // ensure directory is a sub-folder of baseDir
1264
    for (int i = 0; i < baseDirNameCount; i++) {
7✔
1265
      if (!path.getName(i).toString().equals(baseDir.getName(i).toString())) {
10✔
1266
        return null;
2✔
1267
      }
1268
    }
1269
    Path result = path;
2✔
1270
    while (delta > 0) {
2✔
1271
      result = result.getParent();
3✔
1272
      delta--;
2✔
1273
    }
1274
    return result;
2✔
1275
  }
1276

1277
  @Override
1278
  public List<Path> listChildrenMapped(Path dir, Function<Path, Path> filter) {
1279

1280
    if (!Files.isDirectory(dir)) {
5✔
1281
      return List.of();
2✔
1282
    }
1283
    List<Path> children = new ArrayList<>();
4✔
1284
    try (Stream<Path> childStream = Files.list(dir)) {
3✔
1285
      Iterator<Path> iterator = childStream.iterator();
3✔
1286
      while (iterator.hasNext()) {
3✔
1287
        Path child = iterator.next();
4✔
1288
        Path filteredChild = filter.apply(child);
5✔
1289
        if (filteredChild != null) {
2✔
1290
          if (filteredChild == child) {
3!
1291
            LOG.trace("Accepted file {}", child);
5✔
1292
          } else {
1293
            LOG.trace("Accepted file {} and mapped to {}", child, filteredChild);
×
1294
          }
1295
          children.add(filteredChild);
5✔
1296
        } else {
1297
          LOG.trace("Ignoring file {} according to filter", child);
4✔
1298
        }
1299
      }
1✔
1300
    } catch (IOException e) {
×
1301
      throw new IllegalStateException("Failed to find children of directory " + dir, e);
×
1302
    }
1✔
1303
    return children;
2✔
1304
  }
1305

1306
  @Override
1307
  public boolean isEmptyDir(Path dir) {
1308

1309
    return listChildren(dir, f -> true).isEmpty();
6✔
1310
  }
1311

1312
  @Override
1313
  public boolean isNonEmptyFile(Path file) {
1314

1315
    if (Files.isRegularFile(file)) {
5✔
1316
      return (getFileSize(file) > 0);
10✔
1317
    }
1318
    return false;
2✔
1319
  }
1320

1321
  private long getFileSize(Path file) {
1322

1323
    try {
1324
      return Files.size(file);
3✔
1325
    } catch (IOException e) {
×
1326
      LOG.warn("Failed to determine size of file {}: {}", file, e.toString(), e);
×
1327
      return 0;
×
1328
    }
1329
  }
1330

1331

1332

1333
  @Override
1334
  public Path findExistingFile(String fileName, List<Path> searchDirs) {
1335

1336
    for (Path dir : searchDirs) {
10!
1337
      Path filePath = dir.resolve(fileName);
4✔
1338
      try {
1339
        if (Files.exists(filePath)) {
5✔
1340
          return filePath;
2✔
1341
        }
1342
      } catch (Exception e) {
×
1343
        throw new IllegalStateException("Unexpected error while checking existence of file " + filePath + " .", e);
×
1344
      }
1✔
1345
    }
1✔
1346
    return null;
×
1347
  }
1348

1349
  @Override
1350
  public boolean setWritable(Path file, boolean writable) {
1351

1352
    if (!Files.exists(file)) {
5✔
1353
      return false;
2✔
1354
    }
1355
    try {
1356
      // POSIX
1357
      PosixFileAttributeView posix = Files.getFileAttributeView(file, PosixFileAttributeView.class);
7✔
1358
      if (posix != null) {
2!
1359
        Set<PosixFilePermission> permissions = new HashSet<>(posix.readAttributes().permissions());
7✔
1360
        boolean changed;
1361
        if (writable) {
2!
1362
          changed = permissions.add(PosixFilePermission.OWNER_WRITE);
5✔
1363
        } else {
1364
          changed = permissions.remove(PosixFilePermission.OWNER_WRITE);
×
1365
        }
1366
        if (changed) {
2!
1367
          posix.setPermissions(permissions);
×
1368
        }
1369
        return true;
2✔
1370
      }
1371

1372
      // Windows
1373
      DosFileAttributeView dos = Files.getFileAttributeView(file, DosFileAttributeView.class);
×
1374
      if (dos != null) {
×
1375
        dos.setReadOnly(!writable);
×
1376
        return true;
×
1377
      }
1378

1379
      LOG.debug("Failed to set writing permission for file {}", file);
×
1380
      return false;
×
1381

1382
    } catch (IOException e) {
×
1383
      LOG.debug("Error occurred when trying to set writing permission for file {}: {}", file, e.toString(), e);
×
1384
      return false;
×
1385
    }
1386
  }
1387

1388
  @Override
1389
  public void makeExecutable(Path path, boolean confirm) {
1390

1391
    if (Files.exists(path)) {
5✔
1392
      if (skipPermissionsIfWindows(path)) {
4!
1393
        return;
×
1394
      }
1395
      PathPermissions existingPermissions = getFilePermissions(path);
4✔
1396
      PathPermissions executablePermissions = existingPermissions.makeExecutable();
3✔
1397
      boolean update = (executablePermissions != existingPermissions);
7✔
1398
      if (update) {
2✔
1399
        if (confirm) {
2!
1400
          boolean yesContinue = this.context.question(
×
1401
              "We want to execute {} but this command seems to lack executable permissions!\n"
1402
                  + "Most probably the tool vendor did forget to add x-flags in the binary release package.\n"
1403
                  + "Before running the command, we suggest to set executable permissions to the file:\n"
1404
                  + "{}\n"
1405
                  + "For security reasons we ask for your confirmation so please check this request.\n"
1406
                  + "Changing permissions from {} to {}.\n"
1407
                  + "Do you confirm to make the command executable before running it?", path.getFileName(), path, existingPermissions, executablePermissions);
×
1408
          if (!yesContinue) {
×
1409
            return;
×
1410
          }
1411
        }
1412
        setFilePermissions(path, executablePermissions, false);
6✔
1413
      } else {
1414
        LOG.trace("Executable flags already present so no need to set them for file {}", path);
4✔
1415
      }
1416
    } else {
1✔
1417
      LOG.warn("Cannot set executable flag on file that does not exist: {}", path);
4✔
1418
    }
1419
  }
1✔
1420

1421
  @Override
1422
  public PathPermissions getFilePermissions(Path path) {
1423

1424
    PathPermissions pathPermissions;
1425
    String info = "";
2✔
1426
    if (SystemInfoImpl.INSTANCE.isWindows()) {
3!
1427
      info = "mocked-";
×
1428
      if (Files.isDirectory(path)) {
×
1429
        pathPermissions = PathPermissions.MODE_RWX_RX_RX;
×
1430
      } else {
1431
        Path parent = path.getParent();
×
1432
        if ((parent != null) && (parent.getFileName().toString().equals("bin"))) {
×
1433
          pathPermissions = PathPermissions.MODE_RWX_RX_RX;
×
1434
        } else {
1435
          pathPermissions = PathPermissions.MODE_RW_R_R;
×
1436
        }
1437
      }
×
1438
    } else {
1439
      Set<PosixFilePermission> permissions;
1440
      try {
1441
        // Read the current file permissions
1442
        permissions = Files.getPosixFilePermissions(path);
5✔
1443
      } catch (IOException e) {
×
1444
        throw new RuntimeException("Failed to get permissions for " + path, e);
×
1445
      }
1✔
1446
      pathPermissions = PathPermissions.of(permissions);
3✔
1447
    }
1448
    LOG.trace("Read {}permissions of {} as {}.", info, path, pathPermissions);
17✔
1449
    return pathPermissions;
2✔
1450
  }
1451

1452
  @Override
1453
  public void setFilePermissions(Path path, PathPermissions permissions, boolean logErrorAndContinue) {
1454

1455
    if (skipPermissionsIfWindows(path)) {
4!
1456
      return;
×
1457
    }
1458
    try {
1459
      LOG.debug("Setting permissions for {} to {}", path, permissions);
5✔
1460
      // Set the new permissions
1461
      Files.setPosixFilePermissions(path, permissions.toPosix());
5✔
1462
    } catch (IOException e) {
×
1463
      String message = "Failed to set permissions to " + permissions + " for path " + path;
×
1464
      if (logErrorAndContinue) {
×
1465
        LOG.warn(message, e);
×
1466
      } else {
1467
        throw new RuntimeException(message, e);
×
1468
      }
1469
    }
1✔
1470
  }
1✔
1471

1472
  private boolean skipPermissionsIfWindows(Path path) {
1473

1474
    if (SystemInfoImpl.INSTANCE.isWindows()) {
3!
1475
      LOG.trace("Windows does not have file permissions hence omitting for {}", path);
×
1476
      return true;
×
1477
    }
1478
    return false;
2✔
1479
  }
1480

1481
  @Override
1482
  public void touch(Path file) {
1483

1484
    if (Files.exists(file)) {
5✔
1485
      try {
1486
        Files.setLastModifiedTime(file, FileTime.fromMillis(System.currentTimeMillis()));
5✔
1487
      } catch (IOException e) {
×
1488
        throw new IllegalStateException("Could not update modification-time of " + file, e);
×
1489
      }
1✔
1490
    } else {
1491
      try {
1492
        Files.createFile(file);
5✔
1493
      } catch (IOException e) {
1✔
1494
        throw new IllegalStateException("Could not create empty file " + file, e);
8✔
1495
      }
1✔
1496
    }
1497
  }
1✔
1498

1499
  @Override
1500
  public String readFileContent(Path file) {
1501

1502
    LOG.trace("Reading content of file from {}", file);
4✔
1503
    if (!Files.exists((file))) {
5✔
1504
      LOG.debug("File {} does not exist", file);
4✔
1505
      return null;
2✔
1506
    }
1507
    try {
1508
      String content = Files.readString(file);
3✔
1509
      LOG.trace("Completed reading {} character(s) from file {}", content.length(), file);
7✔
1510
      return content;
2✔
1511
    } catch (IOException e) {
×
1512
      throw new IllegalStateException("Failed to read file " + file, e);
×
1513
    }
1514
  }
1515

1516
  @Override
1517
  public void writeFileContent(String content, Path file, boolean createParentDir) {
1518

1519
    if (createParentDir) {
2✔
1520
      mkdirs(file.getParent());
4✔
1521
    }
1522
    if (content == null) {
2!
1523
      content = "";
×
1524
    }
1525
    LOG.trace("Writing content with {} character(s) to file {}", content.length(), file);
7✔
1526
    if (Files.exists(file)) {
5✔
1527
      LOG.info("Overriding content of file {}", file);
4✔
1528
    }
1529
    try {
1530
      Files.writeString(file, content);
6✔
1531
      LOG.trace("Wrote content to file {}", file);
4✔
1532
    } catch (IOException e) {
×
1533
      throw new RuntimeException("Failed to write file " + file, e);
×
1534
    }
1✔
1535
  }
1✔
1536

1537
  @Override
1538
  public List<String> readFileLines(Path file) {
1539

1540
    LOG.trace("Reading lines of file from {}", file);
4✔
1541
    if (!Files.exists(file)) {
5✔
1542
      LOG.warn("File {} does not exist", file);
4✔
1543
      return null;
2✔
1544
    }
1545
    try {
1546
      List<String> content = Files.readAllLines(file);
3✔
1547
      LOG.trace("Completed reading {} lines from file {}", content.size(), file);
7✔
1548
      return content;
2✔
1549
    } catch (IOException e) {
×
1550
      throw new IllegalStateException("Failed to read file " + file, e);
×
1551
    }
1552
  }
1553

1554
  @Override
1555
  public void writeFileLines(List<String> content, Path file, boolean createParentDir) {
1556

1557
    if (createParentDir) {
2!
1558
      mkdirs(file.getParent());
×
1559
    }
1560
    if (content == null) {
2!
1561
      content = List.of();
×
1562
    }
1563
    LOG.trace("Writing content with {} lines to file {}", content.size(), file);
7✔
1564
    if (Files.exists(file)) {
5✔
1565
      LOG.debug("Overriding content of file {}", file);
4✔
1566
    }
1567
    try {
1568
      Files.write(file, content);
6✔
1569
      LOG.trace("Wrote lines to file {}", file);
4✔
1570
    } catch (IOException e) {
×
1571
      throw new RuntimeException("Failed to write file " + file, e);
×
1572
    }
1✔
1573
  }
1✔
1574

1575
  @Override
1576
  public void readProperties(Path file, Properties properties) {
1577

1578
    try (Reader reader = Files.newBufferedReader(file)) {
3✔
1579
      properties.load(reader);
3✔
1580
      LOG.debug("Successfully loaded {} properties from {}", properties.size(), file);
7✔
1581
    } catch (IOException e) {
×
1582
      throw new IllegalStateException("Failed to read properties file: " + file, e);
×
1583
    }
1✔
1584
  }
1✔
1585

1586
  @Override
1587
  public void writeProperties(Properties properties, Path file, boolean createParentDir) {
1588

1589
    if (createParentDir) {
2✔
1590
      mkdirs(file.getParent());
4✔
1591
    }
1592
    try (Writer writer = Files.newBufferedWriter(file)) {
5✔
1593
      properties.store(writer, null); // do not get confused - Java still writes a date/time header that cannot be omitted
4✔
1594
      LOG.debug("Successfully saved {} properties to {}", properties.size(), file);
7✔
1595
    } catch (IOException e) {
×
1596
      throw new IllegalStateException("Failed to save properties file during tests.", e);
×
1597
    }
1✔
1598
  }
1✔
1599

1600
  @Override
1601
  public void readIniFile(Path file, IniFile iniFile) {
1602

1603
    if (!Files.exists(file)) {
5✔
1604
      LOG.debug("INI file {} does not exist.", iniFile);
4✔
1605
      return;
1✔
1606
    }
1607
    List<String> iniLines = readFileLines(file);
4✔
1608
    IniSection currentIniSection = iniFile.getInitialSection();
3✔
1609
    for (String line : iniLines) {
10✔
1610
      if (line.trim().startsWith("[")) {
5✔
1611
        currentIniSection = iniFile.getOrCreateSection(line);
5✔
1612
      } else if (line.isBlank() || IniComment.COMMENT_SYMBOLS.contains(line.trim().charAt(0))) {
11✔
1613
        currentIniSection.addComment(line);
4✔
1614
      } else {
1615
        int index = line.indexOf('=');
4✔
1616
        if (index > 0) {
2!
1617
          currentIniSection.setPropertyLine(line);
3✔
1618
        }
1619
      }
1620
    }
1✔
1621
  }
1✔
1622

1623
  @Override
1624
  public void writeIniFile(IniFile iniFile, Path file, boolean createParentDir) {
1625

1626
    String iniString = iniFile.toString();
3✔
1627
    writeFileContent(iniString, file, createParentDir);
5✔
1628
  }
1✔
1629

1630
  @Override
1631
  public Duration getFileAge(Path path) {
1632

1633
    if (Files.exists(path)) {
5✔
1634
      try {
1635
        long currentTime = System.currentTimeMillis();
2✔
1636
        long fileModifiedTime = Files.getLastModifiedTime(path).toMillis();
6✔
1637
        return Duration.ofMillis(currentTime - fileModifiedTime);
5✔
1638
      } catch (IOException e) {
×
1639
        LOG.warn("Could not get modification-time of {}.", path, e);
×
1640
      }
×
1641
    } else {
1642
      LOG.debug("Path {} is missing - skipping modification-time and file age check.", path);
4✔
1643
    }
1644
    return null;
2✔
1645
  }
1646

1647
  @Override
1648
  public boolean isFileAgeRecent(Path path, Duration cacheDuration) {
1649

1650
    Duration age = getFileAge(path);
4✔
1651
    if (age == null) {
2✔
1652
      return false;
2✔
1653
    }
1654
    LOG.debug("The path {} was last updated {} ago and caching duration is {}.", path, age, cacheDuration);
17✔
1655
    return (age.toMillis() <= cacheDuration.toMillis());
10✔
1656
  }
1657
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc