From patchwork Mon Oct 4 15:08:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 66696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E08EFB70CE for ; Tue, 5 Oct 2010 02:08:42 +1100 (EST) Received: (qmail 14056 invoked by alias); 4 Oct 2010 15:08:38 -0000 Received: (qmail 14044 invoked by uid 22791); 4 Oct 2010 15:08:36 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 15:08:28 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8397ECB0245; Mon, 4 Oct 2010 17:08:26 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sYdjr+5ix4op; Mon, 4 Oct 2010 17:08:26 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 6DBCCCB0244; Mon, 4 Oct 2010 17:08:26 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 1118DD9BB4; Mon, 4 Oct 2010 17:08:23 +0200 (CEST) Date: Mon, 4 Oct 2010 17:08:23 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Vincent Celier Subject: [Ada] Interpretation of Form parameter for Ada.Directories.Copy_File Message-ID: <20101004150823.GA32676@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The Form parameter of procedure Copy_File is now interpreted. Two fields are recognized: preserv= (no_attributes, all_attributes or timestamps) and mode= (copy, overwrite or append). Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-04 Vincent Celier * a-direct.adb (Copy_File): Interpret the Form parameter and call System.OS_Lib.Copy_File to do the work accordingly. Raise Use_Error if the Form parameter contains an incorrect value for field preserve= or mode=. * a-direct.ads (Create_Directory, Create_Path): Indicate that the Form parameter is ignored. (Copy_File): Indicate the interpretation of the Form parameter. Index: a-direct.adb =================================================================== --- a-direct.adb (revision 164906) +++ a-direct.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2004-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2004-2010, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -42,6 +42,7 @@ with Ada.Characters.Handling; use Ada with System.CRTL; use System.CRTL; with System.OS_Lib; use System.OS_Lib; with System.Regexp; use System.Regexp; +with System.File_IO; use System.File_IO; with System; @@ -301,9 +302,11 @@ package body Ada.Directories is Target_Name : String; Form : String := "") is - pragma Unreferenced (Form); Success : Boolean; + Mode : Copy_Mode := Overwrite; + Preserve : Attribute := None; + begin -- First, the invalid cases @@ -322,10 +325,70 @@ package body Ada.Directories is raise Use_Error with "target """ & Target_Name & """ is a directory"; else - -- The implementation uses System.OS_Lib.Copy_File, with parameters - -- suitable for all platforms. + if Form'Length > 0 then + declare + Formstr : String (1 .. Form'Length + 1); + V1, V2 : Natural; + + begin + + -- Acquire form string, setting required NUL terminator + + Formstr (1 .. Form'Length) := Form; + Formstr (Formstr'Last) := ASCII.NUL; + + -- Convert form string to lower case + + for J in Formstr'Range loop + if Formstr (J) in 'A' .. 'Z' then + Formstr (J) := + Character'Val (Character'Pos (Formstr (J)) + 32); + end if; + end loop; + + -- Check Form + + Form_Parameter (Formstr, "mode", V1, V2); + + if V1 = 0 then + Mode := Overwrite; + + elsif Formstr (V1 .. V2) = "copy" then + Mode := Copy; + + elsif Formstr (V1 .. V2) = "overwrite" then + Mode := Overwrite; + + elsif Formstr (V1 .. V2) = "append" then + Mode := Append; + + else + raise Use_Error with "invalid Form"; + end if; + + Form_Parameter (Formstr, "preserve", V1, V2); + + if V1 = 0 then + Preserve := None; + + elsif Formstr (V1 .. V2) = "timestamps" then + Preserve := Time_Stamps; + + elsif Formstr (V1 .. V2) = "all_attributes" then + Preserve := Full; + + elsif Formstr (V1 .. V2) = "no_attributes" then + Preserve := None; + + else + raise Use_Error with "invalid Form"; + end if; + end; + end if; + + -- The implementation uses System.OS_Lib.Copy_File - Copy_File (Source_Name, Target_Name, Success, Overwrite, None); + Copy_File (Source_Name, Target_Name, Success, Mode, Preserve); if not Success then raise Use_Error with "copy of """ & Source_Name & """ failed"; Index: a-direct.ads =================================================================== --- a-direct.ads (revision 164906) +++ a-direct.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 2004-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2004-2010, Free Software Foundation, Inc. -- -- -- -- This specification is derived for use with GNAT from AI-00248, which is -- -- expected to be a part of a future expected revised Ada Reference Manual. -- @@ -104,6 +104,8 @@ package Ada.Directories is -- identification of a directory. The exception Use_Error is propagated if -- the external environment does not support the creation of a directory -- with the given name (in the absence of Name_Error) and form. + -- + -- The Form parameter is ignored. procedure Delete_Directory (Directory : String); -- Deletes an existing empty directory with name Directory. The exception @@ -129,6 +131,8 @@ package Ada.Directories is -- The exception Use_Error is propagated if the external environment does -- not support the creation of any directories with the given name (in the -- absence of Name_Error) and form. + -- + -- The Form parameter is ignored. procedure Delete_Tree (Directory : String); -- Deletes an existing directory with name Directory. The directory and @@ -172,6 +176,41 @@ package Ada.Directories is -- not support the creating of the file with the name given by Target_Name -- and form given by Form, or copying of the file with the name given by -- Source_Name (in the absence of Name_Error). + -- + -- Interpretation of the Form parameter: + -- The Form parameter is case-insensitive. + -- Two fields are recognized in the Form parameter: + -- preserve= + -- mode= + -- starts immediatey after the character '=' and ends with the + -- character immediatey preceding the next comma (',') or with the last + -- character of the parameter. + -- The only possible values for preserve= are: + -- no_attributes: do not try to preserve any file attributes. This is + -- the default if no preserve= is found in Form. + -- all_attributes: try to preserve all file attributes (timestamps, + -- access rights). + -- timestamps: preserve the timestamp of the copied file, but not the + -- other file attributes. + -- The only possible values for mode= are: + -- copy: only do the copy if the destination file does not already + -- exist. If it already exist, Copy_File fails. + -- overwrite: copy the file in all cases. Overwite an aready existing + -- destination file. + -- append: append the original file to the destination file. If the + -- destination file does not exist, the destination file is + -- a copy of the source file. + -- When mode=append, the field preserve=, if it exists, is not + -- taken into account. + -- If the Form parameter includes one or both of the fields and the value + -- or values are incorrect, Copy_file fails with Use_Error. + -- Examples of correct Forms: + -- Form => "preserve=no_attributes,mode=overwrite" (the default) + -- Form => "mode=append" + -- Form => "mode=copy, preserve=all_attributes" + -- Examples of incorrect Forms + -- Form => "preserve=junk" + -- Form => "mode=internal, preserve=timestamps" ---------------------------------------- -- File and directory name operations --