public Properties update()

in maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java [89:138]


    public Properties update(Path path, Map<String, String> updates) {
        Properties props = new Properties();
        try {
            Files.createDirectories(path.getParent());
        } catch (IOException e) {
            LOGGER.warn("Failed to create tracking file parent '{}'", path, e);
            throw new UncheckedIOException(e);
        }

        synchronized (getMutex(path)) {
            try {
                long fileSize;
                try {
                    fileSize = Files.size(path);
                } catch (IOException e) {
                    fileSize = 0L;
                }
                try (FileChannel fileChannel = FileChannel.open(
                                path, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
                        FileLock unused = fileLock(fileChannel, Math.max(1, fileSize), false)) {
                    if (fileSize > 0) {
                        props.load(Channels.newInputStream(fileChannel));
                    }

                    for (Map.Entry<String, String> update : updates.entrySet()) {
                        if (update.getValue() == null) {
                            props.remove(update.getKey());
                        } else {
                            props.setProperty(update.getKey(), update.getValue());
                        }
                    }

                    LOGGER.debug("Writing tracking file '{}'", path);
                    ByteArrayOutputStream stream = new ByteArrayOutputStream(1024 * 2);
                    props.store(
                            stream,
                            "NOTE: This is a Maven Resolver internal implementation file"
                                    + ", its format can be changed without prior notice.");
                    fileChannel.position(0);
                    int written = fileChannel.write(ByteBuffer.wrap(stream.toByteArray()));
                    fileChannel.truncate(written);
                }
            } catch (IOException e) {
                LOGGER.warn("Failed to write tracking file '{}'", path, e);
                throw new UncheckedIOException(e);
            }
        }

        return props;
    }