contrib/showstack.py
author Adam Simpkins <simpkins@fb.com>
Tue, 26 Apr 2016 15:32:59 -0700
branchstable
changeset 29017 07be86828e79
parent 28522 f2fe7b199bb4
child 35656 c9eb92fb87b7
permissions -rw-r--r--
util: fix race in makedirs() Update makedirs() to ignore EEXIST in case someone else has already created the directory in question. Previously the ensuredirs() function existed, and was nearly identical to makedirs() except that it fixed this race. Unfortunately ensuredirs() was only used in 3 places, and most code uses the racy makedirs() function. This fixes makedirs() to be non-racy, and replaces calls to ensuredirs() with makedirs(). In particular, mercurial.scmutil.origpath() used the racy makedirs() code, which could cause failures during "hg update" as it tried to create backup directories. This does slightly change the behavior of call sites using ensuredirs(): previously ensuredirs() would throw EEXIST if the path existed but was a regular file instead of a directory. It did this by explicitly checking os.path.isdir() after getting EEXIST. The makedirs() code did not do this and swallowed all EEXIST errors. I kept the makedirs() behavior, since it seemed preferable to avoid the extra stat call in the common case where this directory already exists. If the path does happen to be a file, the caller will almost certainly fail with an ENOTDIR error shortly afterwards anyway. I checked the 3 existing call sites of ensuredirs(), and this seems to be the case for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26123
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# showstack.py - extension to dump a Python stack trace on signal
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
# binds to both SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs)
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
28522
f2fe7b199bb4 showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26123
diff changeset
     5
from __future__ import absolute_import
f2fe7b199bb4 showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26123
diff changeset
     6
import signal
f2fe7b199bb4 showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26123
diff changeset
     7
import sys
f2fe7b199bb4 showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26123
diff changeset
     8
import traceback
26123
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
def sigshow(*args):
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
    sys.stderr.write("\n")
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
    traceback.print_stack(args[1], limit=10, file=sys.stderr)
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
    sys.stderr.write("----\n")
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
def extsetup(ui):
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
    signal.signal(signal.SIGQUIT, sigshow)
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
    try:
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
        signal.signal(signal.SIGINFO, sigshow)
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
    except AttributeError:
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
        pass