@@ -8,7 +8,6 @@ use std::ffi::{CString, OsStr, OsString};
88use std:: fs:: { self , File } ;
99use std:: io:: { self , Write } ;
1010use std:: os:: fd:: { AsRawFd , FromRawFd , RawFd } ;
11- use std:: os:: raw:: { c_char, c_int, c_uint} ;
1211use std:: os:: unix:: ffi:: OsStrExt ;
1312use std:: path:: { Component , Path } ;
1413use std:: process:: Command ;
@@ -28,23 +27,6 @@ use super::utils::{
2827 schedule_update_job,
2928} ;
3029
31- const O_RDONLY : c_int = 0 ;
32- const O_WRONLY : c_int = 1 ;
33- const O_CREAT : c_int = 0o100 ;
34- const O_EXCL : c_int = 0o200 ;
35- const O_DIRECTORY : c_int = 0o200000 ;
36- const O_NOFOLLOW : c_int = 0o400000 ;
37- const O_CLOEXEC : c_int = 0o2000000 ;
38- const O_PATH : c_int = 0o10000000 ;
39- const ELOOP : i32 = 40 ;
40-
41- unsafe extern "C" {
42- fn open ( pathname : * const c_char , flags : c_int , ...) -> c_int ;
43- fn openat ( dirfd : c_int , pathname : * const c_char , flags : c_int , ...) -> c_int ;
44- fn mkdirat ( dirfd : c_int , pathname : * const c_char , mode : c_uint ) -> c_int ;
45- fn unlinkat ( dirfd : c_int , pathname : * const c_char , flags : c_int ) -> c_int ;
46- }
47-
4830#[ derive( Debug ) ]
4931pub struct PublishJobInstance {
5032 pub job_id : i32 ,
@@ -366,7 +348,7 @@ fn open_or_create_destination_directory(
366348 Ok ( directory) => Ok ( directory) ,
367349 Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => {
368350 let name = c_string_for_path_component ( name, destination_path) ?;
369- let result = unsafe { mkdirat ( parent_fd, name. as_ptr ( ) , 0o755 ) } ;
351+ let result = unsafe { libc :: mkdirat ( parent_fd, name. as_ptr ( ) , 0o755 ) } ;
370352 if result != 0 {
371353 let err = io:: Error :: last_os_error ( ) ;
372354 if err. kind ( ) != io:: ErrorKind :: AlreadyExists {
@@ -401,7 +383,7 @@ fn destination_directory_error(
401383 destination_path : & Path ,
402384 err : io:: Error ,
403385) -> JobError {
404- if err. raw_os_error ( ) == Some ( ELOOP ) {
386+ if err. raw_os_error ( ) == Some ( libc :: ELOOP ) {
405387 return unsafe_screenshot_destination ( destination_path, "is a symlink" ) ;
406388 }
407389
@@ -425,10 +407,15 @@ fn destination_directory_error(
425407
426408fn open_source_file ( path : & Path ) -> JobResult < File > {
427409 let path_name = c_string_for_path ( path) ?;
428- let fd = unsafe { open ( path_name. as_ptr ( ) , O_RDONLY | O_CLOEXEC | O_NOFOLLOW ) } ;
410+ let fd = unsafe {
411+ libc:: open (
412+ path_name. as_ptr ( ) ,
413+ libc:: O_RDONLY | libc:: O_CLOEXEC | libc:: O_NOFOLLOW ,
414+ )
415+ } ;
429416 if fd < 0 {
430417 let err = io:: Error :: last_os_error ( ) ;
431- if err. raw_os_error ( ) == Some ( ELOOP ) {
418+ if err. raw_os_error ( ) == Some ( libc :: ELOOP ) {
432419 return Err ( unsafe_screenshot_source ( path, "is a symlink" ) ) ;
433420 }
434421 return Err ( unsafe_screenshot_source (
@@ -480,7 +467,7 @@ fn remove_existing_destination_file(
480467 destination_path : & Path ,
481468) -> JobResult < ( ) > {
482469 let existing = openat_path_no_follow ( parent_dir. as_raw_fd ( ) , name) . map_err ( |err| {
483- if err. raw_os_error ( ) == Some ( ELOOP ) {
470+ if err. raw_os_error ( ) == Some ( libc :: ELOOP ) {
484471 unsafe_screenshot_destination ( destination_path, "is a symlink" )
485472 } else {
486473 unsafe_screenshot_destination (
@@ -518,7 +505,7 @@ fn remove_existing_destination_file(
518505 drop ( existing) ;
519506
520507 let name = c_string_for_path_component ( name, destination_path) ?;
521- let result = unsafe { unlinkat ( parent_dir. as_raw_fd ( ) , name. as_ptr ( ) , 0 ) } ;
508+ let result = unsafe { libc :: unlinkat ( parent_dir. as_raw_fd ( ) , name. as_ptr ( ) , 0 ) } ;
522509 if result != 0 {
523510 return Err ( unsafe_screenshot_destination (
524511 destination_path,
@@ -536,9 +523,9 @@ fn open_dir_path_no_follow(path: &Path) -> Result<File, io::Error> {
536523 let path_name = c_string_for_path ( path)
537524 . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidInput , err. to_string ( ) ) ) ?;
538525 let fd = unsafe {
539- open (
526+ libc :: open (
540527 path_name. as_ptr ( ) ,
541- O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW ,
528+ libc :: O_RDONLY | libc :: O_CLOEXEC | libc :: O_DIRECTORY | libc :: O_NOFOLLOW ,
542529 )
543530 } ;
544531 if fd < 0 {
@@ -552,10 +539,10 @@ fn openat_dir_no_follow(parent_fd: RawFd, name: &OsStr) -> Result<File, io::Erro
552539 let name = CString :: new ( name. as_bytes ( ) )
553540 . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidInput , err. to_string ( ) ) ) ?;
554541 let fd = unsafe {
555- openat (
542+ libc :: openat (
556543 parent_fd,
557544 name. as_ptr ( ) ,
558- O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW ,
545+ libc :: O_RDONLY | libc :: O_CLOEXEC | libc :: O_DIRECTORY | libc :: O_NOFOLLOW ,
559546 )
560547 } ;
561548 if fd < 0 {
@@ -568,7 +555,13 @@ fn openat_dir_no_follow(parent_fd: RawFd, name: &OsStr) -> Result<File, io::Erro
568555fn openat_path_no_follow ( parent_fd : RawFd , name : & OsStr ) -> Result < File , io:: Error > {
569556 let name = CString :: new ( name. as_bytes ( ) )
570557 . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidInput , err. to_string ( ) ) ) ?;
571- let fd = unsafe { openat ( parent_fd, name. as_ptr ( ) , O_PATH | O_CLOEXEC | O_NOFOLLOW ) } ;
558+ let fd = unsafe {
559+ libc:: openat (
560+ parent_fd,
561+ name. as_ptr ( ) ,
562+ libc:: O_PATH | libc:: O_CLOEXEC | libc:: O_NOFOLLOW ,
563+ )
564+ } ;
572565 if fd < 0 {
573566 Err ( io:: Error :: last_os_error ( ) )
574567 } else {
@@ -580,10 +573,10 @@ fn openat_create_new(parent_fd: RawFd, name: &OsStr) -> Result<File, io::Error>
580573 let name = CString :: new ( name. as_bytes ( ) )
581574 . map_err ( |err| io:: Error :: new ( io:: ErrorKind :: InvalidInput , err. to_string ( ) ) ) ?;
582575 let fd = unsafe {
583- openat (
576+ libc :: openat (
584577 parent_fd,
585578 name. as_ptr ( ) ,
586- O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC | O_NOFOLLOW ,
579+ libc :: O_WRONLY | libc :: O_CREAT | libc :: O_EXCL | libc :: O_CLOEXEC | libc :: O_NOFOLLOW ,
587580 0o644 ,
588581 )
589582 } ;
0 commit comments