Merge ~pappacena/turnip:os-link-failure-log into turnip:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: ccda14f2674a1269246d38a74e1285e7d03c867e
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/turnip:os-link-failure-log
Merge into: turnip:master
Diff against target: 64 lines (+29/-4)
1 file modified
turnip/api/store.py (+29/-4)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+391728@code.launchpad.net

Commit message

Adding more logs for os.link failures

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
ccda14f... by Thiago F. Pappacena

Catching explicit exception

Revision history for this message
Thiago F. Pappacena (pappacena) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/api/store.py b/turnip/api/store.py
2index e50dccf..b00c83b 100644
3--- a/turnip/api/store.py
4+++ b/turnip/api/store.py
5@@ -227,13 +227,23 @@ def write_packed_refs(root, packable_refs):
6 b'^%s\n' % (peeled_oid.hex.encode('ascii'),))
7
8
9-def import_into_subordinate(sub_root, from_root):
10+def get_file_mode(path):
11+ if not os.path.exists(path):
12+ return None
13+ try:
14+ return oct(os.stat(path).st_mode)
15+ except Exception:
16+ return None
17+
18+
19+def import_into_subordinate(sub_root, from_root, log=None):
20 """Import all of a repo's objects and refs into another.
21
22 The refs may clobber existing ones. Refs that can be packed are
23 returned as a dictionary rather than imported immediately, and should be
24 written using `write_packed_refs`.
25 """
26+ log = log if log else logger
27 for dirname in os.listdir(os.path.join(from_root, 'objects')):
28 # We want to hardlink any children of the loose fanout or pack
29 # directories.
30@@ -249,7 +259,20 @@ def import_into_subordinate(sub_root, from_root):
31 sub_path = os.path.join(sub_root, 'objects', dirname, name)
32 if not os.path.isfile(from_path) or os.path.exists(sub_path):
33 continue
34- os.link(from_path, sub_path)
35+ try:
36+ os.link(from_path, sub_path)
37+ except Exception as e:
38+ log.critical(
39+ "Error in import_into_subordinate while executing "
40+ "os.link(%s, %s): %s" % (from_path, sub_path, e))
41+ log.info(
42+ "File modes: from_path: %s / from_path_dir: %s / "
43+ "sub_path: %s / sub_path_dir: %s" %
44+ (get_file_mode(from_path),
45+ get_file_mode(os.path.dirname(from_path)),
46+ get_file_mode(sub_path),
47+ get_file_mode(os.path.dirname(sub_path))))
48+ raise
49
50 # Copy over the refs.
51 # TODO: This should ensure that we don't overwrite anything. The
52@@ -292,8 +315,10 @@ def init_repo(repo_path, clone_from=None, clone_refs=False,
53 packable_refs = {}
54 if os.path.exists(os.path.join(clone_from, 'turnip-subordinate')):
55 packable_refs.update(import_into_subordinate(
56- sub_path, os.path.join(clone_from, 'turnip-subordinate')))
57- packable_refs.update(import_into_subordinate(sub_path, clone_from))
58+ sub_path, os.path.join(clone_from, 'turnip-subordinate'),
59+ log=log))
60+ packable_refs.update(import_into_subordinate(
61+ sub_path, clone_from, log=log))
62
63 log.info("Running write_packed_refs(%s, %s)" %
64 (sub_path, packable_refs))

Subscribers

People subscribed via source and target branches