Drillster / drone-volume-cache

Drone plugin for caching to a locally mounted volume
MIT License
109 stars 43 forks source link

Fix file cache with subdirectories #17

Closed Sharsie closed 6 years ago

Sharsie commented 6 years ago

This PR fixes a bug when using the cache for simple files.

Current behaviour: The file is taken from the specified directory and cached into the /cache/owner/repo/job/ dir When the restore happens it is again taken from a specified directory and restored to the current working dir (without the subdir context)

Rebuild consider the following file structure root.file subdir/sub.file

  restore-cache:
    image: drillster/drone-volume-cache
    restore: true
    mount:
      - root.file
      - subdir/subdir.file
    volumes:
      - /drone/cache:/cache`

During rebuild you endup with /cache/owner/repo/job/root.file /cache/owner/repo/job/sub.file

PR: This patch first checks for the directory where the file is (using dirname), creates it in the cache directory and then rsyncs the file into the subdir (if any)

Same thing happens during restore, first check for the subdir in the project, create it with mkdir -p, then restore it using rsync

mjwwit commented 6 years ago

Thanks for the PR! It looks good and seems to be working exactly as you say.

Sharsie commented 6 years ago

Perfect thanks! :)