Browse Source

Fixed reckless clobbering if file existed

Alois Mahdal 12 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
 Make executable script for you and heat up vim.  Accepts filename as parameter.
26
 Make executable script for you and heat up vim.  Accepts filename as parameter.
27
 
27
 
28
 1.  try to guess type from name (e.g. .pl -> perl)
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
 3.  chmod it to `0755` (yeah, hardcoded `0755`, no smartness here whatsoever)
30
 3.  chmod it to `0755` (yeah, hardcoded `0755`, no smartness here whatsoever)
31
 4.  try to heat up `vim` or `editor` for you.
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
 ### timestamp.pl ###
34
 ### timestamp.pl ###
39
 
35
 

+ 2
- 2
bin/mkexec.pl View File

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