git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Lukashov <michael.lukashov@gmail.com>
To: msysgit <msysgit@googlegroups.com>
Cc: Michael Lukashov <michael.lukashov@gmail.com>,
	git@vger.kernel.org, Sebastian Schuberth <sschuberth@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [msysGit] [PATCH] Installer: Create builtins as symbolic links on Vista
Date: Fri, 15 Jan 2010 22:06:59 +0000	[thread overview]
Message-ID: <1263593219-6032-1-git-send-email-michael.lukashov@gmail.com> (raw)

When create builtins, first try to use CreateSymbolicLinkW function.
If symbolic link creating fails, hard links are created.

Tested under WinXP (both FAT32 and NTFS), Vista and Win7.

This patch applies on top of ss/installer-improvements branch.

Signed-off-by: Michael Lukashov <michael.lukashov@gmail.com>
---
 share/WinGit/install.iss |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss
index 91eac9c..f64f754 100644
--- a/share/WinGit/install.iss
+++ b/share/WinGit/install.iss
@@ -83,8 +83,10 @@ Type: dirifempty; Name: {app}\home
 
 // Note: Since we are using the Unicode version of Inno Setup, "String" is a Unicode
 // string, and thus we need to call the "W" (Wide-String) Windows API variant.
+function CreateSymbolicLink(lpFileName,lpExistingFileName:String;lpSecurityAttributes:Integer):Boolean;
+external 'CreateSymbolicLinkW@Kernel32.dll stdcall setuponly delayload';
 function CreateHardLink(lpFileName,lpExistingFileName:String;lpSecurityAttributes:Integer):Boolean;
-external 'CreateHardLinkW@Kernel32.dll stdcall setuponly';
+external 'CreateHardLinkW@Kernel32.dll stdcall setuponly delayload';
 
 const
     // Git Path options.
@@ -474,7 +476,11 @@ var
     IsNTFS:Boolean;
     FindRec:TFindRec;
     RootKey:Integer;
+    Version:TWindowsVersion;
+    LinkCreated:Boolean;
 begin
+    GetWindowsVersionEx(Version);
+
     if CurStep<>ssPostInstall then begin
         Exit;
     end;
@@ -511,13 +517,25 @@ begin
             for i:=0 to Count do begin
                 FileName:=AppDir+'\'+BuiltIns[i];
 
-                // On non-NTFS partitions, create hard links.
-                if (FileExists(FileName) and (not DeleteFile(FileName))) or
-                   (not CreateHardLink(FileName,AppDir+'\bin\git.exe',0)) then begin
-                    Log('Line {#emit __LINE__}: Unable to create hard link "'+FileName+'", will try to copy files.');
-                    IsNTFS:=False;
+                // First check if file exists.
+                if (FileExists(FileName) and (not DeleteFile(FileName))) then begin
+                    Log('Line {#emit __LINE__}: Unable to delete file "'+FileName);
                     Break;
                 end;
+                // Try to create symbolic link
+                if Version.Major>=6 then
+                try
+                  LinkCreated:=CreateSymbolicLink(FileName,AppDir+'\bin\git.exe',0);
+                except
+                  LinkCreated:=False;
+                end;
+                // Try to create hard link
+                if (not LinkCreated) and
+                   (not CreateHardLink(FileName,AppDir+'\bin\git.exe',0)) then begin
+                  Log('Line {#emit __LINE__}: Unable to create hard link "'+FileName+'", will try to copy files.');
+                  IsNTFS:=False;
+                  Break;
+                end;
             end;
 
             Log('Line {#emit __LINE__}: Successfully created built-in aliases as hard links.');
-- 
1.6.6.1536.g1ac8c

             reply	other threads:[~2010-01-15 22:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-15 22:06 Michael Lukashov [this message]
2010-01-16  0:41 ` [msysGit] [PATCH] Installer: Create builtins as symbolic links on Vista Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263593219-6032-1-git-send-email-michael.lukashov@gmail.com \
    --to=michael.lukashov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=msysgit@googlegroups.com \
    --cc=sschuberth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).