[PATCH 2/7] [cmd/attrib] Support relative paths as args

Ann and Jason Edmeades jason at edmeades.me.uk
Mon Nov 5 16:22:24 CST 2012


Handle a parameter to attrib which is not in the current directory.

[Fixes 2 todos in the cmd tests!]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121105/cd5dc726/attachment.html>
-------------- next part --------------
From 8e99742044d7eed7ed6238afd8a0bb3ac149f0c8 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Thu, 25 Oct 2012 22:42:46 +0100
Subject: [PATCH 2/7] [cmd/attrib] Support relative paths as args

Handle a parameter to attrib which is not in the current directory.

[Fixes 2 todos in the cmd tests!]
---
 programs/attrib/attrib.c                 |   19 ++++++++++++++-----
 programs/cmd/tests/test_builtins.cmd.exp |    4 ++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/programs/attrib/attrib.c b/programs/attrib/attrib.c
index ca15980..25117cc 100644
--- a/programs/attrib/attrib.c
+++ b/programs/attrib/attrib.c
@@ -129,11 +129,11 @@ int wmain(int argc, WCHAR *argv[])
     WIN32_FIND_DATAW fd;
     WCHAR flags[] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'};
     WCHAR name[MAX_PATH];
+    WCHAR *namepart;
     WCHAR curdir[MAX_PATH];
     DWORD attrib_set = 0;
     DWORD attrib_clear = 0;
     const WCHAR help_option[] = {'/','?','\0'};
-    const WCHAR slash[]  = {'\\','\0'};
     const WCHAR start[]  = {'*','\0'};
     int i = 1;
 
@@ -143,13 +143,11 @@ int wmain(int argc, WCHAR *argv[])
     }
 
     /* By default all files from current directory are taken into account */
-    GetCurrentDirectoryW(sizeof(curdir)/sizeof(WCHAR), curdir);
-    strcatW(curdir, slash);
-    strcpyW(name, curdir);
-    strcatW(name, start);
+    strcpyW(name, start);
 
     while (i < argc) {
         WCHAR *param = argv[i++];
+        WINE_TRACE("Processing arg: '%s'\n", wine_dbgstr_w(param));
         if ((param[0] == '+') || (param[0] == '-')) {
             DWORD attrib = 0;
             switch (param[1]) {
@@ -178,6 +176,15 @@ int wmain(int argc, WCHAR *argv[])
         }
     }
 
+    /* Name may be a relative or explicit path, so calculate curdir based on
+       current locations, stripping off the filename                         */
+    WINE_TRACE("Supplied name: '%s'\n", wine_dbgstr_w(name));
+    GetFullPathNameW(name, sizeof(curdir)/sizeof(WCHAR), curdir, &namepart);
+    WINE_TRACE("Result: '%s'\n", wine_dbgstr_w(curdir));
+    strcpyW(name, curdir);
+    if (namepart) *namepart = 0x00;
+
+    /* Search for files based on the location and filespec supplied */
     hff = FindFirstFileW(name, &fd);
     if (hff == INVALID_HANDLE_VALUE) {
         ATTRIB_wprintf(ATTRIB_LoadMessage(STRING_FILENOTFOUND), name);
@@ -195,6 +202,8 @@ int wmain(int argc, WCHAR *argv[])
                 fd.dwFileAttributes |= attrib_set;
                 if (!fd.dwFileAttributes)
                     fd.dwFileAttributes |= FILE_ATTRIBUTE_NORMAL;
+                strcpyW(name, curdir);
+                strcatW(name, fd.cFileName);
                 SetFileAttributesW(name, fd.dwFileAttributes);
             } else {
                 static const WCHAR fmt[] = {'%','1',' ',' ',' ',' ',' ','%','2','\n','\0'};
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 8a7e3fa..42f578d 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -959,14 +959,14 @@ foo original contents
 Read-only file not deleted
 Read-only file forcibly deleted
 --- recursive behaviour
- at todo_wine@A            @pwd@\foobar\baz\level2 at or_broken@A          @pwd@\foobar\baz\level2 at or_broken@A       I    @pwd@\foobar\baz\level2
+A            @pwd@\foobar\baz\level2 at or_broken@A          @pwd@\foobar\baz\level2 at or_broken@A       I    @pwd@\foobar\baz\level2
 @todo_wine at A    R       @pwd@\foobar\level1 at or_broken@A    R     @pwd@\foobar\level1 at or_broken@A    R  I    @pwd@\foobar\level1
 @todo_wine at A    R       @pwd@\foobar\baz\level2 at or_broken@A    R     @pwd@\foobar\baz\level2 at or_broken@A    R  I    @pwd@\foobar\baz\level2
 A            @pwd@\foobar\bar at or_broken@A          @pwd@\foobar\bar at or_broken@A       I    @pwd@\foobar\bar
 --- folders processing
              @pwd@\foobar at or_broken@           @pwd@\foobar at or_broken@        I    @pwd@\foobar
 @todo_wine@     R       @pwd@\foobar\baz at or_broken@     R     @pwd@\foobar\baz at or_broken@           @pwd@\foobar\baz at or_broken@     R  I    @pwd@\foobar\baz
- at todo_wine@A            @pwd@\foobar\baz\toto at or_broken@A          @pwd@\foobar\baz\toto at or_broken@A       I    @pwd@\foobar\baz\toto
+A            @pwd@\foobar\baz\toto at or_broken@A          @pwd@\foobar\baz\toto at or_broken@A       I    @pwd@\foobar\baz\toto
 toto
 lulu
 file created in read-only dir
-- 
1.7.9.5


More information about the wine-patches mailing list