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

Add a command to tag a file/files with TTL #1

Open
nikolay opened this issue Sep 23, 2014 · 7 comments
Open

Add a command to tag a file/files with TTL #1

nikolay opened this issue Sep 23, 2014 · 7 comments

Comments

@nikolay
Copy link

nikolay commented Sep 23, 2014

This would be nice as it could be used from other scripts.

@tdlm
Copy link
Owner

tdlm commented Sep 23, 2014

Do you mean tagging with a general self-destruct tag and then reading in the TTL as another tag?

@nikolay
Copy link
Author

nikolay commented Sep 23, 2014

This is what I meant:

./self-destruct.sh ~/Pr0n/*.mpg --after 1d

@tdlm
Copy link
Owner

tdlm commented Sep 24, 2014

Thanks. I like it and am working on that in a branch.

@mauvm
Copy link
Contributor

mauvm commented Oct 7, 2014

@tdlm Can you push anything semi-working on that branch? I'd like to help. Also it would be great if you could do --after 10m or --after 3d.

@tdlm
Copy link
Owner

tdlm commented Oct 8, 2014

@mauvm I haven't had a chance to work on this in a few days. I actually got stuck on a way to parse the time without resorting to dependencies. I too would like this sort of format!

The path I was going down was just porting that input into the 'date' command like so:

$ date && date -v +10M
Tue Oct  7 19:03:24 PDT 2014
Tue Oct  7 19:13:24 PDT 2014

Using date -v +10M or date -v +${SOME_VAR} it seems would work when altered to just output seconds:

$ date -r 0 -v +10M +"%s"
600
$ date -r 0 -v +1d +"%s"
86400
$ date -r 0 -v +3d +"%s"
259200

This is fine and dandy. The only real trouble there would be security on the command input for date and making sure people know the difference between '10M' and '10m' because it's a big one. I almost think you would want a confirmation unless you specified --force|-f.

Any input here is appreciated.

@mauvm
Copy link
Contributor

mauvm commented Oct 8, 2014

@tdlm Running date -r 0 -v +10M gives me date: invalid option -- 'v'. So I'm not sure what's the difference here. Are you on OS X 10.9.5 too?

What works for me is date -d "+3 Minutes". This also eliminates your problem. Because you can simply substitute the modifier with the tag name: date -d "+$TAG_NAME".

I was thinking more along the lines of also allowing tags like "3 Days". After a quick Google search I found that you can get all tags by running:

mdfind -0 "(kMDItemUserTags == '*')" | xargs -0 mdls -name kMDItemUserTags | grep '^    ' | cut -c5- | cut -d , -f 1 | sort -u

Which results in something like:

3 Days
1 Day
Green

This enables us to make the run command dynamic by reading all tags (with regexes for example) and translating them to the required timestamp. This eventually replaces all the hardcoded delete commands, like secure_delete_files_for_tag_after_seconds "1 Minute" 60.

Finally we can add a command that adds the desired tag:

self-destruct ~/Pr0n/*.mpg --after="3 Days"

Let me know what you think.

@mauvm
Copy link
Contributor

mauvm commented Oct 8, 2014

@nikolay I found a really simple solution:

brew install tag
tag --add "1 Day" ~/Pr0n/*.mpg

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

3 participants