• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * "find_lock.exe", for Windows only.
19  */
20 
21 #ifdef _WIN32
22 
23 #include "utils.h"
24 #include "find_lock.h"
25 #include <io.h>
26 #include <fcntl.h>
27 
main(int argc,char * argv[])28 int main(int argc, char* argv[]) {
29 
30     gIsConsole = true; // tell utils to to print errors to stderr
31     gIsDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL);
32     CPath dirPath;
33     bool doPrintUsage = false;
34 
35     for (int i = 1; i < argc; i++) {
36         if (strncmp(argv[i], "-d", 2) == 0) {
37             gIsDebug = true;
38 
39         } else if (dirPath.isEmpty()) {
40             dirPath.set(argv[i]);
41 
42         } else {
43             doPrintUsage = true;
44         }
45     }
46 
47     if (dirPath.isEmpty()) {
48         fprintf(stderr, "Error: Missing directory path\n");
49         doPrintUsage = true;
50 
51     } else if (!dirPath.dirExists()) {
52         fprintf(stderr, "Error: '%s' is not a valid directory.\n", dirPath.cstr());
53         return 1;
54     }
55 
56     if (doPrintUsage) {
57         printf(
58             "Usage: find_lock.exe [options] sdk_directory_path\n"
59             "\n"
60             "Outputs the names of modules that are locking the given directory.\n"
61             "Returns code 0 when found, 1 when not found.\n"
62             "\n"
63             "Options:\n"
64             "-h / -help   : This help.\n"
65             "-t / -test   : Internal test.\n"
66             );
67         return 2;
68     }
69 
70     CString result;
71     if (findLock(dirPath, &result)) {
72         fflush(stdout);
73         fflush(stderr);
74         printf("%s", result.cstr());
75         return 0;
76     }
77     return 1;
78 }
79 
80 #endif /* _WIN32 */
81