10
10
from bs4 import BeautifulSoup
11
11
import urllib .request
12
12
import re
13
+ import shutil
13
14
import fosslight_util .constant as constant
14
15
import fosslight_dependency .constant as const
15
16
from fosslight_dependency ._package_manager import PackageManager , get_url_to_purl
@@ -24,6 +25,8 @@ class Go(PackageManager):
24
25
is_run_plugin = False
25
26
dn_url = 'https://pkg.go.dev/'
26
27
tmp_file_name = 'tmp_go_list.json'
28
+ go_work = 'go.work'
29
+ tmp_go_work = 'go.work.tmp'
27
30
28
31
def __init__ (self , input_dir , output_dir ):
29
32
super ().__init__ (self .package_manager_name , self .dn_url , input_dir , output_dir )
@@ -33,6 +36,8 @@ def __init__(self, input_dir, output_dir):
33
36
def __del__ (self ):
34
37
if os .path .isfile (self .tmp_file_name ):
35
38
os .remove (self .tmp_file_name )
39
+ if os .path .isfile (self .tmp_go_work ):
40
+ shutil .move (self .tmp_go_work , self .go_work )
36
41
37
42
def parse_dependency_tree (self , go_deptree_txt ):
38
43
for line in go_deptree_txt .split ('\n ' ):
@@ -49,6 +54,9 @@ def parse_dependency_tree(self, go_deptree_txt):
49
54
def run_plugin (self ):
50
55
ret = True
51
56
57
+ if os .path .isfile (self .go_work ):
58
+ shutil .move (self .go_work , self .tmp_go_work )
59
+
52
60
logger .info ("Execute 'go list -m -mod=mod -json all' to obtain package info." )
53
61
cmd = f"go list -m -mod=mod -json all > { self .tmp_file_name } "
54
62
@@ -64,6 +72,8 @@ def run_plugin(self):
64
72
if ret_cmd_tree != 0 :
65
73
self .parse_dependency_tree (ret_cmd_tree )
66
74
75
+ if os .path .isfile (self .tmp_go_work ):
76
+ shutil .move (self .tmp_go_work , self .go_work )
67
77
return ret
68
78
69
79
def parse_oss_information (self , f_name ):
0 commit comments