9
9
#include < unistd.h>
10
10
11
11
#include < fmt/format.h>
12
+ #include < wpi/SmallString.h>
12
13
#include < wpi/StringExtras.h>
14
+ #include < wpi/fmt/raw_ostream.h>
13
15
#include < wpi/fs.h>
14
16
#include < wpi/json.h>
15
17
#include < wpi/raw_istream.h>
@@ -56,11 +58,7 @@ void Application::Set(std::string_view appType,
56
58
} else if (appType == " custom" ) {
57
59
return ;
58
60
} else {
59
- wpi::SmallString<64 > msg;
60
- msg = " unrecognized application type '" ;
61
- msg += appType;
62
- msg += " '" ;
63
- onFail (msg);
61
+ onFail (fmt::format (" unrecognized application type '{}'" , appType));
64
62
return ;
65
63
}
66
64
@@ -72,13 +70,13 @@ void Application::Set(std::string_view appType,
72
70
onFail (" could not write " EXEC_HOME " /runCamera" );
73
71
return ;
74
72
}
75
- os << " #!/bin/sh\n " ;
76
- os << TYPE_TAG << ' ' << appType << ' \n ' ;
77
- os << " echo \" Waiting 5 seconds...\"\n " ;
78
- os << " sleep 5\n " ;
79
- if (!appDir.empty ()) os << " cd " << appDir << ' \n ' ;
80
- if (!appEnv.empty ()) os << appEnv << ' \n ' ;
81
- os << " exec " << appCommand << ' \n ' ;
73
+ fmt::print (os, " #!/bin/sh\n " ) ;
74
+ fmt::print (os, " {} {} \n " , TYPE_TAG, appType) ;
75
+ fmt::print (os, " echo \" Waiting 5 seconds...\"\n " ) ;
76
+ fmt::print (os, " sleep 5\n " ) ;
77
+ if (!appDir.empty ()) fmt::print (os, " cd {} \n " , appDir) ;
78
+ if (!appEnv.empty ()) fmt::print (os, " {} \n " , appEnv) ;
79
+ fmt::print (os, " exec {} \n " , appCommand) ;
82
80
}
83
81
84
82
// terminate vision process so it reloads
@@ -97,18 +95,11 @@ void Application::FinishUpload(std::string_view appType, UploadHelper& helper,
97
95
} else if (appType == " upload-python" ) {
98
96
filename = " /uploaded.py" ;
99
97
} else {
100
- wpi::SmallString<64 > msg;
101
- msg = " cannot upload application type '" ;
102
- msg += appType;
103
- msg += " '" ;
104
- onFail (msg);
98
+ onFail (fmt::format (" cannot upload application type '{}'" , appType));
105
99
helper.Close ();
106
100
return ;
107
101
}
108
102
109
- wpi::SmallString<64 > pathname;
110
- pathname = EXEC_HOME;
111
- pathname += filename;
112
103
int fd = helper.GetFD ();
113
104
114
105
// change ownership
@@ -126,6 +117,8 @@ void Application::FinishUpload(std::string_view appType, UploadHelper& helper,
126
117
// close temporary file
127
118
helper.Close ();
128
119
120
+ auto pathname = fmt::format (" {}{}" , EXEC_HOME, filename);
121
+
129
122
// remove old file (need to do this as we can't overwrite a running exe)
130
123
if (unlink (pathname.c_str ()) == -1 ) {
131
124
fmt::print (stderr, " could not remove app executable: {}\n " ,
@@ -151,7 +144,7 @@ wpi::json Application::GetStatusJson() {
151
144
std::error_code ec;
152
145
wpi::raw_fd_istream is (EXEC_HOME " /runCamera" , ec);
153
146
if (ec) {
154
- fmt::print (stderr, " {} " , " could not read " EXEC_HOME " /runCamera\n " );
147
+ fmt::print (stderr, " could not read {} /runCamera\n " , EXEC_HOME );
155
148
return j;
156
149
}
157
150
0 commit comments