in reply to Re^4: Bad file descriptor when trying to close file handle
in thread Bad file descriptor when trying to close file handle

not sure what you mean, I globed the directory after writing to an unlinked file and it was gone.

Probably that file and inode still exist without association to a dir, but how would I recreate it into the dir?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^5: Bad file descriptor when trying to close file handle

Replies are listed 'Best First'.
Re^6: Bad file descriptor when trying to close file handle
by ikegami (Patriarch) on Mar 03, 2022 at 15:28 UTC

    The directory entry is gone, yes. Writing to a file doesn't create directory entries.

    I didn't mention glob at all. Did you try the steps I described? The file is only gone once no directory and no file handles reference it. Also, see the post I just made in parallel to yours.

    $ perl -Mv5.10 -e' open my $o_fh, ">", "a" or die $!; open my $i_fh, "<", "a" or die $!; unlink "a" or die $!; print $o_fh "abc\n" or die $!; $o_fh->flush(); chomp( my $line = <$i_fh> ); say "<$line>"; ' <abc>
      > See the post I just made in parallel to yours.

      I know about inodes

      But the question remains:

      How can I revive/move an "invisible" file into the directory?

      link doesn't seem to accept FHs.

      use strict; use warnings; use Data::Dump qw/ddx/; use autodie; my $dir = "/tmp"; my $file = "$dir/tst_unlink"; open my $fh, ">>", $file; print $fh "ENTRY ".__LINE__; ddx <$file*>; unlink $file; print $fh "ENTRY ".__LINE__; ddx <$file*>; eval { link $fh, "${file}_new"; } or warn $@; eval { link $file, "${file}_new"; } or warn $@; ddx <$file*>; __DATA__
      OUTPUT:
      # open_unlink.pl:16: "/tmp/tst_unlink" # open_unlink.pl:22: () Can't link($fh, '/tmp/tst_unlink_new'): Datei oder Verzeichnis nicht g +efunden at ./open_unlink.pl line 24 Can't link('/tmp/tst_unlink', '/tmp/tst_unlink_new'): Datei oder Verze +ichnis nicht gefunden at ./open_unlink.pl line 26 # open_unlink.pl:29: ()

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      PS: FWIW: I was guessing, I can't run a full diagnosis for every fuzzy bug question, even after reading it thrice.

        How can I revive/move an "invisible" file into the directory?

        I hadn't read the second half of your post, just the part I commented on.

        I don't know if it's possible. I doubt there exists a portable solution, but I suspect Linux might have one.