@@ -20,18 +20,22 @@ from sftp cimport SFTP
2020from utils cimport ssh_string_to_bytes
2121
2222cimport c_sftp
23- from c_ssh cimport ssh_string
23+ from c_ssh cimport ssh_string, uint8_t, uint32_t, uint64_t
2424
2525
2626cdef class SFTPAttributes:
2727
2828 def __cinit__ (self , SFTP sftp ):
2929 self .sftp = sftp
30+ self .self_made = False
3031
3132 def __dealloc__ (self ):
32- if self ._attrs is not NULL :
33+ if self ._attrs is not NULL and not self .self_made :
3334 c_sftp.sftp_attributes_free(self ._attrs)
3435 self ._attrs = NULL
36+ elif self ._attrs is not NULL and self .self_made:
37+ free(self ._attrs)
38+ self ._attrs = NULL
3539
3640 @staticmethod
3741 cdef SFTPAttributes from_ptr(c_sftp.sftp_attributes attrs, SFTP sftp):
@@ -42,13 +46,38 @@ cdef class SFTPAttributes:
4246
4347 @staticmethod
4448 def new_attrs (SFTP sftp ):
49+ cdef SFTPAttributes attrs
4550 cdef c_sftp.sftp_attributes _attrs
4651 with nogil:
4752 _attrs = < c_sftp.sftp_attributes> malloc(
4853 sizeof(c_sftp.sftp_attributes_struct))
4954 if _attrs is NULL :
5055 raise MemoryError
51- return SFTPAttributes.from_ptr(_attrs, sftp)
56+ _attrs.name = b' '
57+ _attrs.longname = b' '
58+ _attrs.flags = 0
59+ _attrs.type = 0
60+ _attrs.size = 0
61+ _attrs.uid = 0
62+ _attrs.gid = 0
63+ _attrs.owner = b' '
64+ _attrs.group = b' '
65+ _attrs.permissions = 0
66+ _attrs.atime64 = 0
67+ _attrs.atime = 0
68+ _attrs.atime_nseconds = 0
69+ _attrs.createtime = 0
70+ _attrs.createtime_nseconds = 0
71+ _attrs.mtime64 = 0
72+ _attrs.mtime = 0
73+ _attrs.mtime_nseconds = 0
74+ _attrs.acl = NULL
75+ _attrs.extended_count = 0
76+ _attrs.extended_type = NULL
77+ _attrs.extended_data = NULL
78+ attrs = SFTPAttributes.from_ptr(_attrs, sftp)
79+ attrs.self_made = True
80+ return attrs
5281
5382 @property
5483 def name (self ):
@@ -68,22 +97,42 @@ cdef class SFTPAttributes:
6897 def flags (self ):
6998 return self ._attrs.flags if self ._attrs is not NULL else None
7099
100+ @flags.setter
101+ def flags (self , uint32_t flags ):
102+ self ._attrs.flags = flags
103+
71104 @property
72105 def type (self ):
73106 return self ._attrs.type if self ._attrs is not NULL else None
74107
108+ @type .setter
109+ def type (self , uint8_t _type ):
110+ self ._attrs.type = _type
111+
75112 @property
76113 def size (self ):
77114 return self ._attrs.size if self ._attrs is not NULL else None
78115
116+ @size.setter
117+ def size (self , uint64_t size ):
118+ self ._attrs.size = size
119+
79120 @property
80121 def uid (self ):
81122 return self ._attrs.uid if self ._attrs is not NULL else None
82123
124+ @uid.setter
125+ def uid (self , uint32_t uid ):
126+ self ._attrs.uid = uid
127+
83128 @property
84129 def gid (self ):
85130 return self ._attrs.gid if self ._attrs is not NULL else None
86131
132+ @gid.setter
133+ def gid (self , uint32_t gid ):
134+ self ._attrs.gid = gid
135+
87136 @property
88137 def owner (self ):
89138 if self ._attrs is NULL :
@@ -104,38 +153,74 @@ cdef class SFTPAttributes:
104153 def permissions (self ):
105154 return self ._attrs.permissions if self ._attrs is not NULL else None
106155
156+ @permissions.setter
157+ def permissions (self , uint32_t permissions ):
158+ self ._attrs.permissions = permissions
159+
107160 @property
108161 def atime64 (self ):
109162 return self ._attrs.atime64 if self ._attrs is not NULL else None
110163
164+ @atime64.setter
165+ def atime64 (self , uint64_t atime ):
166+ self ._attrs.atime64 = atime
167+
111168 @property
112169 def atime (self ):
113170 return self ._attrs.atime if self ._attrs is not NULL else None
114171
172+ @atime.setter
173+ def atime (self , uint32_t atime ):
174+ self ._attrs.atime = atime
175+
115176 @property
116177 def atime_nseconds (self ):
117178 return self ._attrs.atime_nseconds if self ._attrs is not NULL else None
118179
180+ @atime_nseconds.setter
181+ def atime_nseconds (self , uint32_t nseconds ):
182+ self ._attrs.atime_nseconds = nseconds
183+
119184 @property
120185 def createtime (self ):
121186 return self ._attrs.createtime if self ._attrs is not NULL else None
122187
188+ @createtime.setter
189+ def createtime (self , uint64_t createtime ):
190+ self ._attrs.createtime = createtime
191+
123192 @property
124193 def createtime_nseconds (self ):
125194 return self ._attrs.createtime_nseconds if self ._attrs is not NULL else None
126195
196+ @createtime_nseconds.setter
197+ def createtime_nseconds (self , uint32_t nseconds ):
198+ self ._attrs.createtime_nseconds = nseconds
199+
127200 @property
128201 def mtime64 (self ):
129202 return self ._attrs.mtime64 if self ._attrs is not NULL else None
130203
204+ @mtime64.setter
205+ def mtime64 (self , uint64_t mtime ):
206+ self ._attrs.mtime64 = mtime
207+
131208 @property
132209 def mtime (self ):
133210 return self ._attrs.mtime if self ._attrs is not NULL else None
134211
212+ @mtime.setter
213+ def mtime (self , uint32_t mtime ):
214+ self ._attrs.mtime = mtime
215+
135216 @property
136217 def mtime_nseconds (self ):
137218 return self ._attrs.mtime_nseconds if self ._attrs is not NULL else None
138219
220+ @mtime_nseconds.setter
221+ def mtime_nseconds (self , uint32_t nseconds ):
222+ self ._attrs.mtime_nseconds = nseconds
223+
139224 @property
140225 def acl (self ):
141226 if self ._attrs is NULL :
@@ -146,6 +231,10 @@ cdef class SFTPAttributes:
146231 def extended_count (self ):
147232 return self ._attrs.extended_count if self ._attrs is not NULL else None
148233
234+ @extended_count.setter
235+ def extended_count (self , uint32_t count ):
236+ self ._attrs.extended_count = count
237+
149238 @property
150239 def extended_type (self ):
151240 if self ._attrs is NULL :
0 commit comments