Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #210782 > unrolled thread

not wanting to delete somebody's home directory

Started bymick crane <mick.crane@gmail.com>
First post2019-07-05 17:30 +0200
Last post2019-07-05 22:30 +0200
Articles 6 on this page of 26 — 12 participants

Back to article view | Back to linux.debian.user


Contents

  not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:30 +0200
    Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 17:30 +0200
      Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:40 +0200
        Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 17:40 +0200
          Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 17:50 +0200
            Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 18:20 +0200
              Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 19:00 +0200
                Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 19:30 +0200
        Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:40 +0200
    Re: not wanting to delete somebody's home directory songbird <songbird@anthive.com> - 2019-07-05 18:40 +0200
      Re: not wanting to delete somebody's home directory john doe <johndoe65534@mail.com> - 2019-07-05 19:40 +0200
        Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 20:00 +0200
      Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 19:50 +0200
        Re: not wanting to delete somebody's home directory David Wright <deblis@lionunicorn.co.uk> - 2019-07-05 21:10 +0200
          Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 23:00 +0200
        Re: not wanting to delete somebody's home directory Curt <curty@free.fr> - 2019-07-06 10:40 +0200
          Re: not wanting to delete somebody's home directory songbird <songbird@anthive.com> - 2019-07-06 13:10 +0200
            Re: not wanting to delete somebody's home directory Curt <curty@free.fr> - 2019-07-06 14:40 +0200
              Re: not wanting to delete somebody's home directory Wolf Halton <wolf.halton@gmail.com> - 2019-07-06 15:10 +0200
              Re: not wanting to delete somebody's home directory rhkramer@gmail.com - 2019-07-06 16:30 +0200
                Re: not wanting to delete somebody's home directory "Thomas Schmitt" <scdbackup@gmx.net> - 2019-07-06 17:40 +0200
                  Re: not wanting to delete somebody's home directory "Jeremy Nicoll" <jn.ml.dbn.25@letterboxes.org> - 2019-07-06 18:10 +0200
              Re: not wanting to delete somebody's home directory David Wright <deblis@lionunicorn.co.uk> - 2019-07-06 17:20 +0200
      Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 20:00 +0200
        Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 21:10 +0200
    Re: not wanting to delete somebody's home directory David Christensen <dpchrist@holgerdanske.com> - 2019-07-05 22:30 +0200

Page 2 of 2 — ← Prev page 1 [2]


#210843

From"Thomas Schmitt" <scdbackup@gmx.net>
Date2019-07-06 17:40 +0200
Message-ID<ygUX7-6vs-1@gated-at.bofh.it>
In reply to#210839
Hi,

rhkramer@gmail.com wrote:
> You sometimes will end up with a sort that like this:
> 1 11 12 ... 19 2 21 ... 3
> I'm sort of hoping the reason is easy to spot, as I am fighting a headache

Would the following sequence (and the image of a stern looking librarian)
be more intuitive ?

  A AA AB ... AI B BA ... C

Where in this card index box would you insert "D" or "AAAAA" ?

A human would notice if a set of sorting subjects consists entirely
of numbers and then use a numeric sorting criterion.
But the default criterion with the mentioned Perl code is obviously lexical.

The decision between "19" and "2" is made like this:
The single character '1' has a lower sort rank than '2'. So the decision is
made and the '9' is of no importance. "19" comes before "2".

"11" is lower than "12" because the first characters are equal, and
the second character '1' is lower than the second character '2'.

"1" is lower than "11" because there is no second '1' in "1".
Who quits early has the lower rank.


The classic method to make both sorting criteria match is to prepend
'0' characters to the shorter numbers so that all number texts have the
same length.
Then lexical ordering yields

 01 02 03 11 12 ... 19 21


If you want to intensify your headache, see the mathematical constraints
for a usable sorting criterion at
  http://mathworld.wolfram.com/TotallyOrderedSet.html

Beginning at example line 23 of
  https://perldoc.perl.org/functions/sort.html
you can easily cause great sorting confusion by a self-made non-usable
criterion. The rules of rock-paper-scissors are a good start.


Have a nice day :)

Thomas

[toc] | [prev] | [next] | [standalone]


#210845

From"Jeremy Nicoll" <jn.ml.dbn.25@letterboxes.org>
Date2019-07-06 18:10 +0200
Message-ID<ygVqa-6TT-7@gated-at.bofh.it>
In reply to#210843
On Sat, 6 Jul 2019, at 16:37, Thomas Schmitt wrote:

> The classic method to make both sorting criteria match is to prepend
> '0' characters to the shorter numbers so that all number texts have the
> same length.  Then lexical ordering yields
> 
>  01 02 03 11 12 ... 19 21

If you don't know beforehand whether you're aiming for two-digit or 
three- or four-digit numbers an alternative is to number your files from
eg 10000 so they get names

    10001  10002   10003  ..  10021

-- 
Jeremy Nicoll - my opinions are my own.

[toc] | [prev] | [next] | [standalone]


#210841

FromDavid Wright <deblis@lionunicorn.co.uk>
Date2019-07-06 17:20 +0200
Message-ID<ygUDL-6pL-1@gated-at.bofh.it>
In reply to#210833
On Sat 06 Jul 2019 at 12:31:25 (-0000), Curt wrote:
> On 2019-07-06, songbird <songbird@anthive.com> wrote:
> > Curt wrote:
> >> On 2019-07-05, mick crane <mick.crane@gmail.com> wrote:
> > ...
> >>> I'm incrementing the number by the loop and some software sees 2 as 
> >>> bigger that 10 or something like this. I can probably get around that by 
> >>
> >> Not sure exactly what you mean by some software, but you must be sorting
> >> lexicographically (the numbers are treated as strings, in which case
> >> alphabetically speaking 1 goes before 2).
> >>
> >> I don't think anybody's pointed this out yet (to my surprise) so I
> >> thought I would (maybe I missed it), although my ignorance is nearly
> >> total in the matter.
> >
> >   i have no perl programming experience so i could
> > not speak to that issue.
> 
> This wasn't a criticism of anyone but rather an observation.
> 
> In the bash shell I have wondered about this sorting "anomaly" myself and so
> looked it up this very day. As the simple (and pretty obvious, really) answer
> was completely amenable to my intellectual powers, I was kind of enjoying
> myself believing I'd mastered a trivial programming concept and wished to share
> my joyful discovery with the group. That it happened to be the result of the
> OP's explicit interrogation and so proves itself to be on-topic is a matter of
> pure serendipity.
> 
> ;-)
> 
> # sort numerically ascending
> my @articles = sort {$a <=> $b} @files;
>     
> # sort numerically descending
>  my @articles = sort {$b <=> $a} @files;
> 
> The default must be to sort lexicographically.

Um, typically the default sorting method is by the underlying binary
representation of the characters. Anything else means that some
interpretation of the semantics is taking place, eg folding the
cases together, ignoring punctuation, interpreting strings of digits
as numbers, honouring multipliers like k/M/G, interpreting combining
characters, and of course maltreating the binary characters as 8-bit bytes.

It wasn't clear to me where the OP was intending to sort: within perl
or in the shell. As I posted, my recommendation was to rename the
files within perl, but after they've all been generated, in order that
the number of files (and hence the number of digits required) is known.

Cheers,
David.

[toc] | [prev] | [next] | [standalone]


#210802

Frommick crane <mick.crane@gmail.com>
Date2019-07-05 20:00 +0200
Message-ID<ygAF3-2TM-5@gated-at.bofh.it>
In reply to#210794
On 2019-07-05 17:31, songbird wrote:
> mick crane wrote:
>> hello,
>> I doing some code in perl and I'm not very good at it.
>> code makes some images and saves them to a directory.
>> If the directory doesn't exist it gets made and if it does exist all 
>> the
>> files in it get deleted before putting some new ones in.
>> I'm thinking that if I ever give it to somebody it's possible they 
>> might
>> call the directory
>> "~/" or something and end up deleting all their files, which I'd like 
>> to
>> avoid.
>> How would that best be avoided ?
>> Is that something to do with chroot which I don't know anything about.
> 
>   always put things in a subdirectory.
> 
>   there is normally a directory named .local/share/<program-name>/
> used for such things (or create it if it isn't there).
> 
>   if you have any configuration information that can be saved in
> the .config/<program-name>/ directory (or again create it if it
> isn't there).
> 
> 
>   songbird

Ah Ok, I could assert a directory and then the output directory make 
that a subdirectory.
so if they typed "~/"
  "./images_out/~/" would cause an error ?

-- 
Key ID    4BFEBB31

[toc] | [prev] | [next] | [standalone]


#210806

Frommick crane <mick.crane@gmail.com>
Date2019-07-05 21:10 +0200
Message-ID<ygBKO-3KH-5@gated-at.bofh.it>
In reply to#210802
On 2019-07-05 18:56, mick crane wrote:
> On 2019-07-05 17:31, songbird wrote:
>> mick crane wrote:
>>> hello,
>>> I doing some code in perl and I'm not very good at it.
>>> code makes some images and saves them to a directory.
>>> If the directory doesn't exist it gets made and if it does exist all 
>>> the
>>> files in it get deleted before putting some new ones in.
>>> I'm thinking that if I ever give it to somebody it's possible they 
>>> might
>>> call the directory
>>> "~/" or something and end up deleting all their files, which I'd like 
>>> to
>>> avoid.
>>> How would that best be avoided ?
>>> Is that something to do with chroot which I don't know anything 
>>> about.
>> 
>>   always put things in a subdirectory.
>> 
>>   there is normally a directory named .local/share/<program-name>/
>> used for such things (or create it if it isn't there).
>> 
>>   if you have any configuration information that can be saved in
>> the .config/<program-name>/ directory (or again create it if it
>> isn't there).
>> 
>> 
>>   songbird
> 
> Ah Ok, I could assert a directory and then the output directory make
> that a subdirectory.
> so if they typed "~/"
>  "./images_out/~/" would cause an error ?


  a directory called "~/" might be tricky to delete ?

-- 
Key ID    4BFEBB31

[toc] | [prev] | [next] | [standalone]


#210810

FromDavid Christensen <dpchrist@holgerdanske.com>
Date2019-07-05 22:30 +0200
Message-ID<ygD0e-4pB-3@gated-at.bofh.it>
In reply to#210782
On 7/5/19 8:24 AM, mick crane wrote:
> hello, I doing some code in perl and I'm not very good at it. code
> makes some images and saves them to a directory. If the directory
> doesn't exist it gets made and if it does exist all the files in it
> get deleted before putting some new ones in. I'm thinking that if I
> ever give it to somebody it's possible they might call the directory 
> "~/" or something and end up deleting all their files, which I'd like
> to avoid. How would that best be avoided ? Is that something to do
> with chroot which I don't know anything about.

On 7/5/19 8:32 AM, mick crane wrote:
> after they get made I rename them all in consecutive order and if 
> there's other files in there the number order will get messed up.

On 7/5/19 8:38 AM, mick crane wrote:> I  guess the safest thing would be
to keep making new directories called
> the current time and only delete things by hand but still would be
> interested if there is a solution.

On 7/5/19 10:39 AM, mick crane wrote:
> I'm incrementing the number by the loop and some software sees 2 as 
> bigger that 10 or something like this. I can probably get around that
> by adding to a very large number in the loop and calling them that. I
> don't mind deleting them by hand but if I have to run program
> several times to tweak what images look like it slows things down. I
> was interested though if there was some instruction to put at the
> top of the file to make perl think that the directory the file was in
> was "/"

On 7/5/19 10:56 AM, mick crane wrote:
> Ah Ok, I could assert a directory and then the output directory make 
> that a subdirectory. so if they typed "~/" "./images_out/~/" would
> cause an error ?

On 7/5/19 11:59 AM, mick crane wrote:
> a directory called "~/" might be tricky to delete ?

Here are some ideas regarding what to do if files already exist in the 
destination directory:

1.  Prompt the user before deleting each file.

2.  Prompt the user once before deleting all files.

3.  Provide "--yes" and "--no" command line options for pre-answering 
prompts.

4.  Provide a "--force" option that deletes all files without prompting.


If you are serious about programming in Perl, you should buy the Perl 
Cookbook:

http://shop.oreilly.com/product/9780596003135.do

https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch09s03.html

https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch15s02.html


A demo script and command line session follow.


David


2019-07-05 13:17:45 dpchrist@tinkywinky ~/sandbox/perl
$ cat prompt-delete-file.pl
#!perl
# $Header: /var/local/cvs/dpchrist/sandbox/perl/prompt-delete-file.pl,v 
1.3 2019/07/05 20:17:44 dpchrist Exp $
# Demonstrate command-line option and interactive prompt
# by David Paul Christensen dpchrist@holgerdanske.com
# Public Domain

use strict;
use warnings;
use File::Slurp;
use Getopt::Long;

sub prompt
{
     print "@_? ";
     return <STDIN>;
}

### main
{
     my $f = $0 . '.tmp';
     my %opt;

     GetOptions \%opt, 'force';

     unless (-f $f) {
	warn "Writing $f\n";
	write_file $f, "hello, world!\n";
     }

     if ($opt{force} || prompt("Remove '$f' (y/N)") =~ /y/i) {
	warn "Unlinking $f\n";
	unlink $f or die "unlink $f: $!";
     }
}

2019-07-05 13:17:59 dpchrist@tinkywinky ~/sandbox/perl
$ perl prompt-delete-file.pl
Writing prompt-delete-file.pl.tmp
Remove 'prompt-delete-file.pl.tmp' (y/N)?

2019-07-05 13:18:08 dpchrist@tinkywinky ~/sandbox/perl
$ cat prompt-delete-file.pl.tmp
hello, world!

2019-07-05 13:18:13 dpchrist@tinkywinky ~/sandbox/perl
$ perl prompt-delete-file.pl
Remove 'prompt-delete-file.pl.tmp' (y/N)? y
Unlinking prompt-delete-file.pl.tmp

2019-07-05 13:18:19 dpchrist@tinkywinky ~/sandbox/perl
$ cat prompt-delete-file.pl.tmp
cat: prompt-delete-file.pl.tmp: No such file or directory

2019-07-05 13:18:21 dpchrist@tinkywinky ~/sandbox/perl
$ perl prompt-delete-file.pl --force
Writing prompt-delete-file.pl.tmp
Unlinking prompt-delete-file.pl.tmp

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | linux.debian.user


csiph-web