Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--recursive flag for some fs commands #232

Open
ModProg opened this issue Feb 25, 2022 · 8 comments
Open

--recursive flag for some fs commands #232

ModProg opened this issue Feb 25, 2022 · 8 comments
Assignees

Comments

@ModProg
Copy link

ModProg commented Feb 25, 2022

Feature Description

Sometimes it can be quite useful to operate not only on a directory but also all subdirs.
Therefore, I'd like an easy way to get all files in a file tree or compare if any file in one dir is newer than another path.

Describe The Solution You'd Like

a recursive flag for commands like ls or is_path_newer.

For ls the behavior is easily defined: just print all files of any subpath.

For is_path_newer there are technically 3 different possible behaviors:

  • recursive only the one that should be newer
  • recursive only the one that should be older
  • recursive for both.

For my use case, any of these would be fine (I just want to know if any file in the src dir is newer than the build dir), but they could also be made available as 2-3 different flags:

  • recursive-left
  • recursive-right
  • (recursive-both)

There are probably other commands that would benefit from this as well.

@sagiegurari
Copy link
Owner

not sure i want to have recursive on everything. where it makes more sense like copy/move/remove ya, but is path newer feels a bit strange.
how about using the glob command?

handle = glob_array ./somedir/**/*.txt

for path in ${handle}
    echo ${path}
end

@ModProg
Copy link
Author

ModProg commented Mar 1, 2022

how about using the glob command?

That would still result in a bit of a mouthful:

target = glob_array build/**/*
src = glob_array src/**/*

any_newer = false

for src_file in ${src}
    for target_file in ${target}
        if is_path_newer ${src_file} ${target_file}
            any_newer = true
        end
    end
end

if ${any_newer}
    # My actual behaviour
end

But in the end all I would personally need is sagiegurari/cargo-make#611 (comment)

@sagiegurari
Copy link
Owner

your code is wrong. you don't need to walk and glob both source and target.
only source.
that makes the code half the size.

@ModProg
Copy link
Author

ModProg commented Mar 1, 2022

your code is wrong. you don't need to walk and glob both source and target. only source. that makes the code half the size.

Depends on whether the target folder gets touched with every build, but that is probably true in most cases.

@sagiegurari
Copy link
Owner

but you are comparing EVERY source file with EVERY target file. thats wrong. no way you need to do that.
you have
src/file1.src
src/file2.src
target/file1.bin
target/file2.bin

if you glob on both and compare all, why would comparing src/file.src with target/file2.bin will help? file1 and file2 are unrelated.

@ModProg
Copy link
Author

ModProg commented Mar 1, 2022

if you glob on both and compare all, why would comparing src/file.src with target/file2.bin will help? file1 and file2 are unrelated.

Depends on your language if there is a one to one mapping of build artifacts to src files

@sagiegurari
Copy link
Owner

again, based on source you create the target files to check. you don't glob.
and i think there is no way that every source file needs to be checked against every target file.
so is newer onglobs makes, at the moment, little sense to me.
give me one use case please.

@ModProg
Copy link
Author

ModProg commented Mar 1, 2022

and i think there is no way that every source file needs to be checked against every target file.

That is probably true, but I'd rather take the cost of comparing every file with every file than actually figuring out the exact mapping, that's also why sagiegurari/cargo-make#611 (comment) would be sufficient for my use.

Probably a better way to do it would be iterating over both folders and just take the highest timestamp, tho.

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

No branches or pull requests

2 participants