Item978: does not work with files as extracted from tgz

Priority: Low
Current State: Closed
Released In: 1.0.5
Target Release: patch
Applies To: Engine
Reported By: GiulianoProcida
Waiting For:
Last Change By: GiulianoProcida
The InstallationGuide refers to as a helpful tool to rewrite #! interpreter paths.

Unfortunately, the installation .tgz has all the Perl executables as read only and the Perl script dies.

Also, I think the InstallationGuide should refer to both bin and tools directories.

Personally I got around this issue with a bit of shell:

find bin tools -type f | xargs file | grep perl | sed 's,:.*,,' | while read x; do cp -a "$x" "$"; chmod u+w "$"; sed 's,#!/usr/bin/perl,#!/path/to/my/perl/bin/perl,' <"$x" >"$"; chmod u-w "$"; mv "$" "$x"; done

It may be that the 555 permissions in the tar ball were a mistake. Fixing this should be simple. Otherwise (assuming stat and chmod do the right thing), try this change:

    open(F, "<$file") || die $!;
    my $mode = stat(F)[2]; # may need to stat($file) on Win32?
    my $contents = <F>;
    close F;

    my $tmp_file = "$file.tmp_copy"; 
    if( $contents =~ s/^#!\s*\S+/#!$new/s ) {
        open(F, $tmp_file, '>') || die $!;
        print F $contents;
        close F;
        chmod $mode, $tmp_file;
        rename $tmp_file, $file || die $!;
        print "$file modified\n";
    } else {
        print "$file not modified\n"; # incorrect in original

I'm not sure how well this will work on non-Unix machines.

-- GiulianoProcida - 04 Feb 2009

There is a tacit assumption with that you will run it as root, I guess. I think your chmod approach is the right one in this case. The rename call is the most dodgy bit of your patch - I'd use File::Copy::move myself.

-- CrawfordCurrie - 05 Feb 2009

The following patch tests okay on windows and linux. I didn't see the above patch, so already tested the below"

---    (revision 3656)
+++    (working copy)
@@ -68,9 +68,12 @@
     close F;

     if( $contents =~ s/^#!\s*\S+/#!$new/s ) {
+        my $mode = (stat($file))[2];
+        chmod( oct(666), "$file");
         open(F, ">$file") || die $!;
         print F $contents;
         close F;
+        chmod( $mode, "$file");
         print "$file modified\n";
     } else {

-- GiulianoProcida

I decided and Crawford agrees that this fix also goes into 1.0.5

-- KennethLavrsen - 25 Apr 2009

I would never recommend overwriting files in place unless there is a real need for it. You also are still missing the second (cosmetic) fix I gave above.

    } else {
        print "$file not modified\n";

-- GiulianoProcida - 27 Apr 2009

ItemTemplate edit

Summary does not work with files as extracted from tgz
ReportedBy GiulianoProcida
Codebase 1.0.0
SVN Range Foswiki-1.0.0, Thu, 08 Jan 2009, build 1878
AppliesTo Engine
Priority Low
CurrentState Closed
Checkins distro:7a56dcaf530f distro:d432e88abee9 distro:be00a1635856
TargetRelease patch
ReleasedIn 1.0.5
Topic revision: r12 - 27 Apr 2009, GiulianoProcida - This page was cached on 16 Sep 2021 - 19:07.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy