Skip to content

Commit 7a0bfd1

Browse files
committed
Skip through any stub preamble
1 parent 79d6731 commit 7a0bfd1

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

csharp/ql/src/Stubs/make_stubs.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,36 @@
7171
print('Failed to run the query to generate output file.')
7272
exit(1)
7373

74-
# Remove the leading " and trailing " bytes from the file
75-
len = os.stat(outputFile).st_size
76-
f = open(outputFile, "rb")
77-
try:
78-
quote = f.read(6)
79-
if quote != b"\x02\x01\x86'\x85'":
80-
print("Unexpected start characters in file.", quote)
81-
contents = f.read(len-21)
82-
quote = f.read(15)
83-
if quote != b'\x0e\x01\x08#select\x01\x01\x00s\x00':
84-
print("Unexpected end character in file.", quote)
85-
finally:
86-
f.close()
74+
# Remove the leading and trailing bytes from the file
75+
length = os.stat(outputFile).st_size
76+
if length < 20:
77+
contents = b''
78+
else:
79+
f = open(outputFile, "rb")
80+
try:
81+
countTillSlash = 0
82+
foundSlash = False
83+
slash = f.read(1)
84+
while slash != b'':
85+
if slash == b'/':
86+
foundSlash = True
87+
break
88+
countTillSlash += 1
89+
slash = f.read(1)
90+
91+
if not foundSlash:
92+
countTillSlash = 0
93+
94+
f.seek(0)
95+
quote = f.read(countTillSlash)
96+
print("Start characters in file skipped.", quote)
97+
post = b'\x0e\x01\x08#select\x01\x01\x00s\x00'
98+
contents = f.read(length - len(post) - countTillSlash)
99+
quote = f.read(len(post))
100+
if quote != post:
101+
print("Unexpected end character in file.", quote)
102+
finally:
103+
f.close()
87104

88105
f = open(outputFile, "wb")
89106
f.write(contents)

0 commit comments

Comments
 (0)