From 2fcb635790c653bf0b0213acd8de8127fb1930de Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 28 May 2012 20:30:58 -0600 Subject: [PATCH] raco exe: checks on source and destination paths Disallow creating a launcher whose source is the launcher itself, for example. --- collects/compiler/commands/exe.rkt | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/collects/compiler/commands/exe.rkt b/collects/compiler/commands/exe.rkt index b18f17dabc..79254aa879 100644 --- a/collects/compiler/commands/exe.rkt +++ b/collects/compiler/commands/exe.rkt @@ -1,5 +1,5 @@ -#lang scheme/base -(require scheme/cmdline +#lang racket/base +(require racket/cmdline raco/command-name compiler/private/embed launcher/launcher @@ -73,6 +73,23 @@ (extract-base-filename/ss source-file (string->symbol (short-program+command-name)))) (gui))]) + (unless (file-exists? source-file) + (raise-user-error (string->symbol (short-program+command-name)) + "source file does not exist\n path: ~a" source-file)) + (with-handlers ([exn:fail:filesystem? (lambda (exn) (void))]) + (call-with-input-file* dest + (lambda (dest-in) + (call-with-input-file* source-file + (lambda (source-in) + (when (equal? (port-file-identity dest-in) + (port-file-identity source-in)) + (raise-user-error (string->symbol (short-program+command-name)) + (string-append + "source file is the same as the destination file" + "\n source path: ~a" + "\n destination path: ~a") + source-file + dest))))))) (cond [(launcher) (parameterize ([current-launcher-variant (if (3m) '3m 'cgc)])