Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Implements caching to reduce network requests when downloading modules and manifests. Cache is stored in ~/.cache/dmod/dmf-get/ (customizable via DMOD_CACHE_DIR) with separate subdirectories for manifests and packages.

Changes

  • Cache management: Added functions for directory creation, cache key generation (djb2 hash + sanitized URL suffix), file I/O, and cleanup
  • Download integration: Modified DownloadWithCurl() to cache manifests; added DownloadWithCurlNoCache() helper; updated DownloadFile() to cache packages
  • CLI: Added -c/--clear-cache flag
  • Security hardening:
    • Replaced system() calls with safe C functions (mkdir(), unlink(), rmdir())
    • Added path traversal validation in RemoveDirectoryContents()
    • Increased buffer sizes (2048 bytes) with truncation checks
    • Used uint64_t with PRIx64 for portable hash function
    • Replaced fseek()/ftell() with fstat() for reliable file sizes

Usage

# Normal usage - automatic caching
dmf-get mymodule

# Clear cache
dmf-get --clear-cache

# Custom cache location
export DMOD_CACHE_DIR=/custom/path

On first download, manifests and packages are cached. Subsequent requests use cached files without network I/O. All existing tests pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)
  • example.com
    • Triggering command: ../../build/bin/tools/dmf-get ../../build/bin/tools/dmf-get -m manifest.dmm -o output testmod -j ACCEPT (dns block)
    • Triggering command: ../../build/bin/tools/dmf-get ../../build/bin/tools/dmf-get -m manifest_vars.dmm -t arch/x86_64 -o output module1 o (dns block)
    • Triggering command: ../../build/bin/tools/dmf-get ../../build/bin/tools/dmf-get -d deps.dmd -m manifest.dmm -o output fig o etest-populate-s-I (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Dodać cache'owanie manifestów do dmf-get</issue_title>
<issue_description>dmf-get, aby ograniczyć liczbę zapytań o manifest, powinien sobie cache'ować manifesty i zipy w jakiejś znanej ścieżce i czyścić wszystko, jeśli użytkownik przekaże parametr --clear-cache lub -c. </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits December 11, 2025 15:46
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
- Replace system("mkdir -p") with CreateDirectoryRecursive() function
- Replace system("rm -rf") with RemoveDirectoryContents() function
- Add DownloadWithCurlNoCache() to fix cache categorization bug
- Add errno.h and dirent.h includes for new functions

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
- Add path traversal protection in RemoveDirectoryContents
- Increase buffer sizes and add truncation checks (1024→2048 bytes)
- Use uint64_t with PRIx64 for portable hash function
- Replace fseek/ftell with fstat for reliable file size
- Add stdint.h and inttypes.h includes

Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add caching for manifests in dmf-get Add manifest and package caching to dmf-get Dec 11, 2025
Copilot AI requested a review from JohnAmadis December 11, 2025 16:06
@JohnAmadis JohnAmadis marked this pull request as ready for review December 11, 2025 17:43
@JohnAmadis JohnAmadis merged commit 20d7eba into develop Dec 12, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dodać cache'owanie manifestów do dmf-get

2 participants