Rev 3842: (mbp) don't call chdir(''), which fails on SunOS in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Nov 20 04:57:33 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3842
revision-id: pqm at pqm.ubuntu.com-20081120045730-d6ik8z5dfnzcnab6
parent: pqm at pqm.ubuntu.com-20081119075529-9c4jtbifm0igp3vf
parent: mbp at sourcefrog.net-20081120041717-0ay1x181hd3q97r2
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-11-20 04:57:30 +0000
message:
  (mbp) don't call chdir(''), which fails on SunOS
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
    ------------------------------------------------------------
    revno: 3841.1.3
    revision-id: mbp at sourcefrog.net-20081120041717-0ay1x181hd3q97r2
    parent: mbp at sourcefrog.net-20081120041608-9yfmatq3ad0w9oy0
    parent: john at arbash-meinel.com-20081119165407-5sxxlimtvun9fpn8
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Thu 2008-11-20 15:17:17 +1100
    message:
      Merge John's fix for chdir('')
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
        ------------------------------------------------------------
        revno: 3838.1.1
        revision-id: john at arbash-meinel.com-20081119165407-5sxxlimtvun9fpn8
        parent: pqm at pqm.ubuntu.com-20081117034335-el4e1m7v3tnjmnhu
        committer: John Arbash Meinel <john at arbash-meinel.com>
        branch nick: chdir_empty
        timestamp: Wed 2008-11-19 10:54:07 -0600
        message:
          Fix bug #297831 by skipping the chdir call if we have an empty path.
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
          bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
    ------------------------------------------------------------
    revno: 3841.1.2
    revision-id: mbp at sourcefrog.net-20081120041608-9yfmatq3ad0w9oy0
    parent: mbp at sourcefrog.net-20081120023619-kuhhai103uliqavo
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Thu 2008-11-20 15:16:08 +1100
    message:
      Don't call chdir('')
    modified:
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
    ------------------------------------------------------------
    revno: 3841.1.1
    revision-id: mbp at sourcefrog.net-20081120023619-kuhhai103uliqavo
    parent: pqm at pqm.ubuntu.com-20081119075529-9c4jtbifm0igp3vf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: trivial
    timestamp: Thu 2008-11-20 13:36:19 +1100
    message:
      Fix try/finally block after chdir in readdir_pyx
    modified:
      bzrlib/_readdir_pyx.pyx        readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
=== modified file 'NEWS'
--- a/NEWS	2008-11-18 21:43:36 +0000
+++ b/NEWS	2008-11-20 04:17:17 +0000
@@ -30,6 +30,9 @@
     * Better message when the user needs to set their Launchpad ID.
       (Martin Pool, #289148)
 
+    * Don't call the system ``chdir()`` with an empty path. Sun OS seems
+      to give an error in that case. (John Arbash Meinel, #297831)
+
     * TooManyConcurrentRequests no longer occur when a fetch fails and
       tries to abort a write group.  This allows the root cause (e.g. a
       network interruption) to be reported.  (Andrew Bennetts, #297014)

=== modified file 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/_readdir_pyx.pyx	2008-10-07 08:33:16 +0000
+++ b/bzrlib/_readdir_pyx.pyx	2008-11-20 04:17:17 +0000
@@ -283,63 +283,67 @@
     global errno
 
     cwd = getcwd(NULL, 0)
-    if -1 == chdir(path):
-        raise OSError(errno, strerror(errno))
-    the_dir = opendir(".")
-    if NULL == the_dir:
-        raise OSError(errno, strerror(errno))
-    result = []
+    if path != "":
+        # Avoid chdir('') because it causes problems on Sun OS
+        if -1 == chdir(path):
+            raise OSError(errno, strerror(errno))
     try:
-        entry = &sentinel
-        while entry != NULL:
-            # Unlike most libc functions, readdir needs errno set to 0
-            # beforehand so that eof can be distinguished from errors.  See
-            # <https://bugs.launchpad.net/bzr/+bug/279381>
-            while True:
-                errno = 0;
-                entry = readdir(the_dir)
-                if entry == NULL and (errno == EAGAIN or errno == EINTR):
-                    # try again
-                    continue
-                else:
-                    break
-            if entry == NULL:
-                if errno == ENOTDIR or errno == 0:
-                    # We see ENOTDIR at the end of a normal directory.
-                    # As ENOTDIR for read_dir(file) is triggered on opendir,
-                    # we consider ENOTDIR to be 'no error'.
-                    continue
-                else:
-                    raise OSError(errno, strerror(errno))
-            name = entry.d_name
-            if not (name[0] == c"." and (
-                (name[1] == 0) or 
-                (name[1] == c"." and name[2] == 0))
-                ):
-                statvalue = _Stat()
-                stat_result = lstat(entry.d_name, &statvalue._st)
-                if stat_result != 0:
-                    if errno != ENOENT:
+        the_dir = opendir(".")
+        if NULL == the_dir:
+            raise OSError(errno, strerror(errno))
+        try:
+            result = []
+            entry = &sentinel
+            while entry != NULL:
+                # Unlike most libc functions, readdir needs errno set to 0
+                # beforehand so that eof can be distinguished from errors.  See
+                # <https://bugs.launchpad.net/bzr/+bug/279381>
+                while True:
+                    errno = 0;
+                    entry = readdir(the_dir)
+                    if entry == NULL and (errno == EAGAIN or errno == EINTR):
+                        # try again
+                        continue
+                    else:
+                        break
+                if entry == NULL:
+                    if errno == ENOTDIR or errno == 0:
+                        # We see ENOTDIR at the end of a normal directory.
+                        # As ENOTDIR for read_dir(file) is triggered on opendir,
+                        # we consider ENOTDIR to be 'no error'.
+                        continue
+                    else:
                         raise OSError(errno, strerror(errno))
-                    else:
-                        kind = _missing
-                        statvalue = None
-                # We append a 5-tuple that can be modified in-place by the C
-                # api:
-                # inode to sort on (to replace with top_path)
-                # name (to keep)
-                # kind (None, to set)
-                # statvalue (to keep)
-                # abspath (None, to set)
-                PyList_Append(result, (entry.d_ino, entry.d_name, None,
-                    statvalue, None))
+                name = entry.d_name
+                if not (name[0] == c"." and (
+                    (name[1] == 0) or 
+                    (name[1] == c"." and name[2] == 0))
+                    ):
+                    statvalue = _Stat()
+                    stat_result = lstat(entry.d_name, &statvalue._st)
+                    if stat_result != 0:
+                        if errno != ENOENT:
+                            raise OSError(errno, strerror(errno))
+                        else:
+                            kind = _missing
+                            statvalue = None
+                    # We append a 5-tuple that can be modified in-place by the C
+                    # api:
+                    # inode to sort on (to replace with top_path)
+                    # name (to keep)
+                    # kind (None, to set)
+                    # statvalue (to keep)
+                    # abspath (None, to set)
+                    PyList_Append(result, (entry.d_ino, entry.d_name, None,
+                        statvalue, None))
+        finally:
+            if -1 == closedir(the_dir):
+                raise OSError(errno, strerror(errno))
     finally:
         if -1 == chdir(cwd):
             free(cwd)
             raise OSError(errno, strerror(errno))
         free(cwd)
-        if -1 == closedir(the_dir):
-            raise OSError(errno, strerror(errno))
     return result
 
 




More information about the bazaar-commits mailing list