Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:17:41+00:00 2026-06-04T06:17:41+00:00

So I have a rake file like the following: require ‘fileutils’ task :copy do

  • 0

So I have a rake file like the following:

require 'fileutils'

task :copy do
  FileUtils.cp_r 'src', 'target'
end

How can I:

  1. Only copy the files that have changed?
  2. Make the :copy task have a dependency on the src directory so that it will only launch if it needs to? :copy => 'src' and :copy => FileList['src/*'].to_a don’t seem to work.

I can take care of the first question like this:

task :copy do
    sh 'rsync -ru src/* target'
end

I would like to, if reasonably possible, do this with only ruby / rake. This also somewhat takes care of the second question because rsync won’t do anything if no files have changed, but I would like for the rake task to not execute at all if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:17:44+00:00Added an answer on June 4, 2026 at 6:17 am

    To avoid executing the task, Rake needs to know both the target and source and the rule for determining whether to execute the task in order to create the target from the source.

    Normally that is rule is “time modified”, i.e. if source is newer than target then Rake will run the task. You can modify this by providing a Proc as the source dependency. See http://docs.rubyrake.org/user_guide/chapter03.html under “Advanced Rules” (but it does take some experimentation to get your head around what is happening!).

    So your task must depend on the target. If you know the target does not exist it should be easy:

    task :copy => 'target/' do
      sh 'rsync -ru src/ target'  # trailing slash is significant; target will be created
    done
    

    If target exists already it gets much more complicated. You could define a rule for each and every file but frankly I’d just run the rsync and be done with it. Rsync is very fast on local filesystems, running it everytime is just no big deal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following rake file to create a static version of my sinatra
I want to have a rake task that reads a HAML file and creates
I have the following Nokogiri rake task in my Rails (3.1) application: desc Import
I have a Rakefile with a Rake task that I would normally call from
I have a rake task I need to run as a daily job on
I have a rake task to seed an application with random data using the
I have a rake task where I do some checks at the beginning, if
I have a rake task that pulls and parses JSON data over an SSL
I have this little rake task: namespace :db do namespace :test do task :reset
I have managed to get a cron job to run a rake task by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.