Browse Source

Fixed reckless clobbering if file existed

Alois Mahdal 11 years ago
parent
commit
07fb761c58
2 changed files with 3 additions and 7 deletions
  1. 1
    5
      README.md
  2. 2
    2
      bin/mkexec.pl

+ 1
- 5
README.md View File

@@ -26,14 +26,10 @@ of thumb goes without saying: "no green, no commit".
26 26
 Make executable script for you and heat up vim.  Accepts filename as parameter.
27 27
 
28 28
 1.  try to guess type from name (e.g. .pl -> perl)
29
-2.  clobber(!) filename with shebang (based on `which` call)
29
+2.  if filename does not exist, create it with shebang (based on `which` call)
30 30
 3.  chmod it to `0755` (yeah, hardcoded `0755`, no smartness here whatsoever)
31 31
 4.  try to heat up `vim` or `editor` for you.
32 32
 
33
-**Warning**: This clobbers filename without warnings but I'm too lazy to fix
34
-             that.  Either send a patch or make me feel emarrassed enough so
35
-             I'll do it myself.
36
-
37 33
 
38 34
 ### timestamp.pl ###
39 35
 

+ 2
- 2
bin/mkexec.pl View File

@@ -30,7 +30,8 @@ $cmds->{editor}->{run}  = "editor '%s'";
30 30
 
31 31
 
32 32
 if (exists $bang->{$type}) {
33
-	mkexec $name, $bang->{$type};
33
+	-e $name || mkexec $name, $bang->{$type};
34
+	chmod $DEFAULT_MODE, $name;
34 35
     launch_editor $name;
35 36
 } else {
36 37
 	die "unknown type: $type\n";
@@ -53,7 +54,6 @@ sub mkexec {
53 54
 	-W EXE			|| die "file $name is not writable\n";
54 55
 	print EXE "#!$bang\n";
55 56
 	close EXE		|| die "cannot close $name: $!\n";
56
-	chmod $DEFAULT_MODE, $name;
57 57
 }
58 58
 
59 59
 sub get_cmd {