ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "matheusrich (Matheus Richard) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "matheusrich (Matheus Richard)" <noreply@ruby-lang.org>
Subject: [ruby-core:117247] [Ruby master Feature#6337] FileUtils#sync
Date: Wed, 20 Mar 2024 00:38:22 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-107334.20240320003822.137@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6337.20120422091325.137@ruby-lang.org

Issue #6337 has been updated by matheusrich (Matheus Richard).


@trans I'm not sure I understand the proposal. Is this basically cloning the source dir with a different name? could that be the name you want `clone_dir`?

----------------------------------------
Feature #6337: FileUtils#sync
https://bugs.ruby-lang.org/issues/6337#change-107334

* Author: trans (Thomas Sawyer)
* Status: Assigned
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
=begin
I'd like to see some sort of FileUtils#sync method to sync the contents of one directory with another.

Here is a prototype definition:

    #
    # Synchronize a destination directory with a source directory.
    #
    def sync(src, dst, options={})
      src_files = Dir[File.join(src, '**', '*')].map{ |f| f.sub(src+'/', '') }
      dst_files = Dir[File.join(dst, '**', '*')].map{ |f| f.sub(dst+'/', '') }

      removal = dst_files - src_files

      rm_dirs, rm_files = [], []
      removal.each do |f|
        path = File.join(dst, f)
        if File.directory?(path)
          rm_dirs << path
        else
          rm_files << path
        end
      end

      rm_files.each { |f| rm(f) }
      rm_dirs.each  { |d| rmdir(d) }

      src_files.each do |f|
        src_path = File.join(src, f)
        dst_path = File.join(dst, f)
        if File.directory?(src_path)
          mkdir_p(dst_path)
        else
          parent = File.dirname(dst_path) 
          mkdir_p(parent) unless File.directory?(parent)
          install(src_path, dst_path)
        end
      end
    end

I haven't tested this beyond a simple trial. It needs improvement. For one, it probably should be able to handle regular files as arguments too. It also needs to handle verbose and dryrun options properly. Nonetheless, with improvements, would be okay for such to become new feature for FileUtils?

=end




-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

           reply	other threads:[~2024-03-20  0:38 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <redmine.issue-6337.20120422091325.137@ruby-lang.org>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-107334.20240320003822.137@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).